Menus Running a menu action from a script 74
Set myInCopy = CreateObject("InCopy.Application")
Rem Fill in the name of the menu action you want.
Set myMenuAction = myInCopy.MenuActions.Item("$ID/Convert to Note") myKeyStrings = myInCopy.FindKeyStrings(myMenuAction.Name) myString = ""
For Each myKeyString In myKeyStrings myString = myString & myKeyString & vbCr
Next
MsgBox myString
N OTE : It is much better to get the locale-independent name of a MenuAction than of a Menus , MenuItem , or
Submenu
, because the title of a
MenuAction
is more likely to be a single string. Many of the other menu objects return multiple strings when you use the
GetKeyStrings
method.
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 InCopy.
To translate a locale-independent string into the current locale, use the following script fragment (from the
TranslateKeyString tutorial script):
Set myInCopy = CreateObject("InCopy.Application")
Rem Fill in the appropriate key string in the following line.
myString = myInCopy.TranslateKeyString("$ID/Convert to Note")
MsgBox myString
Running a menu action from a script
Any of InCopy’s built-in
MenuActions
can be run from a script. The
MenuAction
does not need to be attached to a
MenuItem
; however, in every other way, running a
MenuItem
from a script is exactly the same as choosing a menu option in the user interface. If selecting the menu option displays a dialog box, running the corresponding MenuAction from a script also displays a dialog box.
The following script shows how to run a
MenuAction
from a script (for the complete script, see
InvokeMenuAction):
Set myInCopy = CreateObject("InCopy.Application")
Rem Get a reference to a menu action.
Set myMenuAction = myInCopy.MenuActions.Item("$ID/Convert to Note")
Rem Run the menu action. The example action will fail if you do not
Rem have text selected.
myMenuAction.Invoke
N OTE : In general, you should not try to automate InCopy processes by scripting menu actions and user-interface selections; InCopy’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 InCopy 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 InCopy 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):