Adobe 65009333 Scripting Guide - Page 69
current selection. If there is no selection, the script in the, disables the menu item. If an
UPC - 883919155852
View all Adobe 65009333 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 69 highlights
Menus Working with script menu actions 69 about to be displayed). Among other things, the script can then change the menu names and/or set the enabled/checked status. In the following sample script, we add an eventListener to the beforeDisplay event that checks the current selection. If there is no selection, the script in the eventListener disables the menu item. If an item is selected, the menu item is enabled, and choosing the menu item displays the type of the first item in the selection. (For the complete script, see BeforeDisplay.) var mySampleScriptAction = app.scriptMenuActions.add("Display Message"); var myEventListener = mySampleScriptAction.eventListeners.add("onInvoke", myOnInvokeHandler, false); var mySampleScriptMenu = app.menus.item("$ID/Main").submenus.add("Script Menu Action"); var mySampleScriptMenuItem = mySampleScriptMenu.menuItems.add(mySampleScriptAction); mySampleScriptMenu.eventListeners.add("beforeDisplay", myBeforeDisplayHandler, false); //JavaScript function to run before the menu item is drawn. function myBeforeDisplayHandler(myEvent){ var mySampleScriptAction = app.scriptMenuActions.item("Display Message"); if(app.documents.length > 0){ if(app.selection.length > 0){ mySampleScriptAction.enabled = true; } else{ mySampleScriptAction.enabled = false; } } else{ mySampleScriptAction.enabled = false; } } //JavaScript function to run when the menu item is selected. function myOnInvokeHandler(myEvent){ myString = app.selection[0].constructor.name; alert("The first item in the selection is a " + myString + "."); }