Localized Menu: the Adventure Continues
The problem of accessing scripts from the context menu of different localizations was described in detail in the article "Access to the script from a localized menu" and specified a year later. The solution methods proposed in those materials, to put it mildly, are far from perfect: it is suggested to manually search for the index of the desired menu and specify it in the script. It is clear that with this approach, in the case of moving the script to another computer, on which another version of the program is installed, with a different localization and a set of updates, the user will have to redo the index search and correct the script each time.
When the topic was again touched upon on the RuDTP forum in one of the discussions recently, Vitaly Batushev, the author of various scripts, one of them is “sZam”, which is known to many users, shared his decision:
Searching for objects by using a loop is not the fastest way, and, according to Vitaly, "unfortunately it is very slow". However, it allows you to solve the existing problem at once for all versions and localizations of InDesign.
Below is one of the examples of how to search for the index of the desired menu, both the context menu and the main one, regardless of the version and localization. It should be borne in mind that behind one or another index may not at all be "hiding" what we assume. For example, the object from the main menu "Table" that is needed in this case will contain the line: "$ID/Table,$ID/kTablePanelTitle,$ID/kPreflightOD_Table,$ID/XML_TableName". And when trying to get the context menu "$ID/RtMouseTable", for example the "$ID/RtMouseTableStrokeWidget" may interfere. The code below is made taking into account these peculiarities.
var menuName = "New table menu item"; var myMenuItem = app.scriptMenuActions.add(menuName); myMenuItem.addEventListener('onInvoke', function(){main();}); function getCurMenu(m, mn){ //The object we need is in the collection of objects m and is called mn var mi = 0; var s = app.findKeyStrings(m[mi].name).toString(); while (!(s.match(mn))){ mi++; s = app.findKeyStrings(m[mi].name).toString(); } return mi; //Return found menu index } var mnu = app.menus[0].submenus[getCurMenu(app.menus[0].submenus, "kTablePanelTitle")]; //Top menu var rMouseMnu = app.menus[getCurMenu(app.menus, "RtMouseTable$")]; //Context menu mnu.menuItems.add(myMenuItem); rMouseMnu.menuSeparators.add(); rMouseMnu.menuItems.add(myMenuItem);
With this algorithm, in order to embed the script into the menu, it is sufficient to pick once a regular expression (lines 13, 14) for the string s.match(mn) at line 7, where s is the full name of the current menu item (as in the examples above), mn is the string composed in a way that it can be contained in the name of just the desired menu.
The scripts on this site, which get embedded in various menus, have now all been updated. If you downloaded them before, and the attempt to embed them in the menu was not successful, download the new versions, try again and, if possible, let us know about the results in the comments.
Scripts available on the site, which are embedded in various menus:
No comments.
Other articles:
- Quick formatting
- Quick Spread Rotate
- Cross-Reference — in Two Clicks
- Access to the script from the localized menu
- Export From InDesign to HTML: How to Tag Character Styles
- Export From InDesign to HTML-2: How to Tag Paragraphs
- Export From InDesign to HTML-3: Tables
- The Script Did Not Appear In the Menu, or One More Time About the Localization
- Export From InDesign to HTML-4: What to Do With Images and Hyperlinks
- How to Access the List of Styles Through the User Interface
Other articles:
- Quick formatting
- Quick Spread Rotate
- Cross-Reference — in Two Clicks
- Access to the script from the localized menu
- Export From InDesign to HTML: How to Tag Character Styles
- Export From InDesign to HTML-2: How to Tag Paragraphs
- Export From InDesign to HTML-3: Tables
- The Script Did Not Appear In the Menu, or One More Time About the Localization
- Export From InDesign to HTML-4: What to Do With Images and Hyperlinks
- How to Access the List of Styles Through the User Interface