Running A Menu Action From A Script; Adding Menus And Menu Items - Adobe 0046100128056 - InDesign - Mac Manual

Javascript
Table of Contents

Advertisement

C
9: Menus
HAPTER
var myString = "";
var myMenuAction = app.menuActions.item("Convert to Note");
var myKeyStrings = app.findKeyStrings(myMenuAction.name);
if(myKeyStrings.constructor.name == "Array"){
for(var myCounter = 0; myCounter < myKeyStrings.length; myCounter ++){
myString += myKeyStrings[myCounter] + "\r";
}
}
else{
myString = myKeyStrings;
}
alert(myString);
N
: It is much better to get the locale-independent name of a
OTE
submenu
objects return multiple strings when you use the
Once you have the locale-independent string you want to use, you can include it in your scripts. Scripts
that use these strings will function properly in locales other than that of your version of InDesign.
To translate a locale-independent string into the current locale, use the following script fragment (from the
TranslateKeyString tutorial script):
var myString = app.translateKeyString("$ID/NotesMenu.ConvertToNote");
alert(myString);

Running a Menu Action from a Script

Any of InDesign's built-in
attached to a
as choosing a menu option in the user interface. For example, If selecting the menu option displays a
dialog box, running the corresponding
The following script shows how to run a
InvokeMenuAction):
//Get a reference to a menu action.
var myMenuAction = app.menuActions.item("$ID/NotesMenu.ConvertToNote");
//Run the menu action. This example action will fail if you do not
//have text selected.
myMenuAction.invoke();
N
: In general, you should not try to automate InDesign processes by scripting menu actions and
OTE
user-interface selections; InDesign's scripting object model provides a much more robust and powerful
way to work. Menu actions depend on a variety of user-interface conditions, like the selection and the
state of the window. Scripts using the object model work with the objects in an InDesign document
directly, which means they do not depend on the user interface; this, in turn, makes them faster and more
consistent.

Adding Menus and Menu Items

Scripts also can create new menus and menu items or remove menus and menu items, just as you can in
the InDesign user interface. The following sample script shows how to duplicate the contents of a
submenu to a new menu in another menu location (for the complete script, see CustomizeMenu):
, because the title of a
menuAction
menuActions
; however, in every other way, running a
menuItem
is more likely to be a single string. Many of the other menu
findKeyStrings
can be run from a script. The
from a script also displays a dialog box.
menuAction
from a script (for the complete script, see
menuAction
Running a Menu Action from a Script 131
than of a
menuAction
method.
does not need to be
menuAction
from a script is exactly the same
menuItem
,
, or
menu
menuItem

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Indesign cs5

Table of Contents