2009-10-20

Add a Main Menu

Below is code to add a main menu at the right side of InDesign's or InCopy's menu bar:

function makeMainMenu(menuName) {
//-------------------------------------------------------------------------
//-- M A K E M A I N M E N U
//-------------------------------------------------------------------------
//-- Generic: Yes.
//-------------------------------------------------------------------------
//-- Purpose: To add the main menu in the menu bar.
//-------------------------------------------------------------------------
//-- Parameters: menuName: A string for the name of the main menu.
//-------------------------------------------------------------------------
//-- Returns: A menu object.
//-------------------------------------------------------------------------
//-- Written by Jon S. Winters.
//-- eps@electronicpublishingsupport.com
//-------------------------------------------------------------------------
try {
//-- OPTIONAL: You may want to try to remove the menu if you are
//-- going to change it radically.
removeMenu(menuName) ;
var aMenu = app.menus.item("$ID/Main").submenus.item(menuName);
aMenu.title ; //-- this errors if the menu doesn't exist, That causes
//-- the menu to be added in the catch statement.

//-- Internal function
function removeMenu (killThisMenu) {
var mySampleScriptMenu = app.menus.item("$ID/Main").submenus.item(killThisMenu);
mySampleScriptMenu.remove();
}
}
catch ( err ) {
var aMenu = app.menus.item("$ID/Main").submenus.add(menuName);
}
return aMenu ;
}
//

No comments:

Post a Comment