EasyManua.ls Logo

Adobe 0046100128056 - InDesign - Mac - Working with Scriptmenuactions

Adobe 0046100128056 - InDesign - Mac
209 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
CHAPTER 9: Menus Working with scriptMenuActions 133
the wording of menu item, or performs other tasks related to the menu. This mechanism is used internally
to change the menu listing of available fonts, recent documents, or open windows.
Working with scriptMenuActions
You can use scriptMenuAction to create a new menuAction whose behavior is implemented through the
script registered to run when the
onInvoke event is triggered.
The following script shows how to create a
scriptMenuAction and attach it to a menu item (for the
complete script, see MakeScriptMenuAction). This script simply displays an alert when the menu item is
selected.
var mySampleScriptAction = app.scriptMenuActions.add("Display Message");
var myEventListener = mySampleScriptAction.eventListeners.add("onInvoke",
function(){alert("This menu item was added by a script.");});
//If the submenu "Script Menu Action" does not already exist, create it.
try{
var mySampleScriptMenu = app.menus.item("$ID/Main").submenus.item(
"Script Menu Action");
mySampleScriptMenu.title;
}
catch (myError){
var mySampleScriptMenu = app.menus.item("$ID/Main").submenus.add
("Script Menu Action");
}
var mySampleScriptMenuItem = mySampleScriptMenu.menuItems.add(mySampleScriptAction);
To remove the menu, submenu, menuItem, and scriptMenuAction created by the above script, run the
following script fragment (from the RemoveScriptMenuAction tutorial script):
#targetengine "session"
var mySampleScriptAction = app.scriptMenuActions.item("Display Message");
mySampleScriptAction.remove();
var mySampleScriptMenu = app.menus.item("$ID/Main").submenus.item
("Script Menu Action");
mySampleScriptMenu.remove();
You also can remove all scriptMenuAction, as shown in the following script fragment (from the
RemoveAllScriptMenuActions tutorial script). This script also removes the menu listings of the
scriptMenuAction, but it does not delete any menus or submenus you might have created.
#targetengine "session"
app.scriptMenuActions.everyItem().remove();
You can create a list of all current scriptMenuActions, as shown in the following script fragment (from
the ListScriptMenuActions tutorial script):

Table of Contents