InDesign Tips & Tricks
Customizing InDesign Context Menu: Adding 'Insert Cross-Reference' to Right-Click
My previous blog post mentioned how much faster it would be to just right-click and have an 'insert cross-reference'. It took a little more than planned, but here is a script to accomplish just that:
( function () {
/* ADD items to CONTEXT MENU
The locale-independent name (aka "key string") for the context menus:
- Layout menu: $ID/RtMouseLayout - when an image is selected
- Default menu: $ID/RtMouseDefault - when nothing is seleced
- Text menu: $ID/RtMouseText - when the mouse is in text, or text is selected
*/
var contextMenu = app.menus.itemByName("$ID/RtMouseText");
var xrefMenu = app.menus.item("$ID/Main").submenus.item("$ID/&Type").submenus.item("$ID/XRefSubMenu");
var refItem = xrefMenu.menuItems.item("$ID/New XRef...");
try {
contextMenu.menuItems.itemByName(refItem.name).remove();
} catch( ex ) {};
contextMenu.menuItems.add(refItem.associatedMenuAction,LocationOptions.AFTER,contextMenu.menuItems.itemByName("$ID/InsertSpecial Footnote"));
})();
You can save the above file as AddCrossRefToContext.jsx and save in your InDesign Startup Script folder, for me that meant in C:\Program Files\Adobe\Adobe InDesign CS5.5\Scripts\startup scripts . Next time you start in-design, if you right-click in a text box you should see the following:
Hurrah! I'll also document how to modify the script to get other menu items instead of cross-references.
First, you need to understand how to get the InDesign locale-unspecific 'key'. To do so fire up "Adobe ExtendScript Toolkit CS5.5", and also open "InDesign CS5.5". Select InDesign as the linked application:
Find the name of the menu item you want to add, for example I'll demonstrate adding the "Odd Page Break" item. This item is located in the following menu structure: Type -> Insert Break Character -> Insert Odd Page Break. We need to find the name of each of those menus/submenus/items.
You also need to decide where in the context menu to go - I'll put it after 'Show hidden characters'.
Some methods for discovering them are discussed in http://forums.adobe.com/message/4061217 . The easiest is running the following command in the Javascript Console (found by John Hawkinson):
app.findKeyStrings(app.menuActions.itemByName("Insert Cross-Reference...").title)
Which gives you the "$ID/New XRef..." you see in the code. For some reason it doesn't seem to work with the break character menu. Using the other method (with 'alt' key) shown in that thread, you can discover the following:
| Menu Name | Command to run in JS Console | ID Result |
| Type | app.findKeyStrings("&Type") | $ID/&Type |
| Insert Break Character | app.findKeyStrings("Insert Brea&k Character") | $ID/Insert Break Menu |
| Odd Page Break | app.findKeyStrings("&Odd Page Break") | $ID/Odd Page Break |
Also figure out the location in the context menu, here I use the other method to find the key:
| Menu Name | Command to run in JS Console | ID Result |
| Show Hidden Characters | app.findKeyStrings(app.menuActions.itemByName("Show Hidden Characters").title) | $ID/Show Hidden Characters |
Finally:
( function () {
var contextMenu = app.menus.itemByName("$ID/RtMouseText");
var xrefMenu = app.menus.item("$ID/Main").submenus.item("$ID/&Type").submenus.item("$ID/Insert Break Menu");
var refItem = xrefMenu.menuItems.item("$ID/Odd Page Break");
try {
contextMenu.menuItems.itemByName(refItem.name).remove();
} catch( ex ) {};
contextMenu.menuItems.add(refItem.associatedMenuAction,LocationOptions.AFTER,contextMenu.menuItems.itemByName("$ID/Show Hidden Characters"));
})();
Newest Blog Posts
-
Customizing InDesign Context Menu: Adding 'Insert Cross-Reference' to Right-Click
2011-12-03 14:36
-
IEEE Style Endnotes/References/Bibliography with InDesign CS5.5
2011-11-30 20:27
-
Original Research Example: Using Coin Cells
2011-10-01 19:28
-
Status Update
2011-10-01 19:25
-
Adding Equations with MathType & MT-Script
2011-08-15 21:47
-
Hiding Part of Cross-Referenced Items in InDesign CS5.5
2011-08-15 19:54
Newest Blog Post Comments