Ok, back at work!
Short answer: there is currently no 'clean' way to do it with the current version of APID. This kind of event is definitely a candidate for addition in a future version, but there is no such thing.
However... there is a workaround that might be 'good enough' for your purposes. I tried it in CS3; as far as I can tell, it
should work in CS2 as well, but I have not tried it out...
Step 1: Add a new page item to one of your master pages, somewhere on the pasteboard (we best put it on a master page so it does not get affected by page deletions - otherwise we might involuntary delete this page item along with the script it contains when deleting a page)
Step 2: attach the following script to the page item via the APID palette
var document = GetDocumentFromChild(theItem);
var lastPageCount = document.extractLabel("pageCount");
if (lastPageCount == null || lastPageCount == "")
{
lastPageCount = document.pages.length;
}
else if (lastPageCount != document.pages.length)
{
PageAddedEvent();
lastPageCount = document.pages.length;
}
document.insertLabel("pageCount",lastPageCount+""); // +"" forces conversion to string
// ***************************
function PageAddedEvent()
{
alert("Page Added or Removed");
}
// ***************************
function GetDocumentFromChild(childItem)
{
var parentDocument = null;
do // do{}while(false); construct; bail out using 'break'
{
//
// Climb the parent chain starting from the child until we cannot
// go any further, or until we hit a 'Document' object
//
while
(
childItem != null
&&
childItem.parent != childItem
&&
! (childItem instanceof Document)
)
{
childItem = childItem.parent;
}
if (! (childItem instanceof Document))
{
break; // bail out
}
parentDocument = childItem;
}
while (false);
return parentDocument;
}
Step 3: Set the event filter to something like 'idle#trigger'. The '#trigger' suffix is a CS3 construct - the CS2 version will ignore the '#trigger' suffix. It causes an idle event to be sent every second or so to a separate ExtendScript engine called 'trigger'. Using a separate engine can help reducing possible interference between this thing and other scripting stuff.
The PageAddedEvent() function will called every time one or more pages are added or removed.
There are disadvantages to this approach: because it's all done at idle time, a sufficiently nimble-moused user can add and delete a page in quick succession, and cause this script to not 'see' the page addition/deletion, but apart from that it seems to work reasonably well.
Hope this helps!
Cheers,
Kris