Problem with adding TabbedPalette using the create document event
Dear forum,
I created a TabbedPalette and now want it to add automatically on start up. My first attempt was to add it to the ‘Startup Scripts’ folder, but this, obviously, didn’t work so I reread the documentation more carefully and found out that this should be done using the create document event.
You can add a palette to an existing browser window at any time (as long as the identifier is unique), and
you can use the create document event to add your palette to new browser windows on creation.
(Bridge CS6 scripting reference, page 87)
Here’s a snippet illustrating the problem:
onCreateDocument = function(event) {
if (event.object instanceof Document && event.type == "create") {
$.writeln("Document is created");
CreateTabbedPalette();
return {handled: true};
}
}
app.eventHandlers.push({handler: onCreateDocument});
function CreateTabbedPalette() {
$.writeln("Entering the 'CreateTabbedPalette' function");
$.writeln("App documents length = " + app.documents.length);
$.writeln("Exiting the 'CreateTabbedPalette' function");
}

It seems that the create document event is triggered before the document is actually created so app.documents.length = 0; as a result, later when I try to add a TabbedPalette to the current document -- app.documents[0] – an error occurs.


Am I doing something wrong, or adding a TabbedPalette via menu item is the only option?
Regards,
Kas
