Quantcast
Channel: Adobe Community : Popular Discussions - InDesign Scripting
Viewing all articles
Browse latest Browse all 15932

[JS] Menu Added via Scripting Moves

$
0
0

I've been able to sucessfully add items to the InDesign menu thanks in part to Marijan Tompa's (tomaxxi) blog post http://indisnip.wordpress.com/2010/08/08/create-customized-menu/

 

My test code (below) creates a new menu, and sucessfully adds two menu items plus a submenu. The submenu is causing me problems. When you first launch InDesign it's created in the proper place (in the middle of the menu). But when you relaunch InDesign, the submenu moves to the top of the menu and never goes back to it's proper position farther down in the menu where it was the first time InDesign was launched.

 

I've searched high and low in this forum, the web and InDesign's documentation and can't figure out how to keep it from moving (I want the menu to be farther down the menu, not at the top). I hope one of you kind souls will help me to control the position of the submenu (and have it stay there across launches).

 

Thanks in advance!

Dan

 

Here's the code I'm working with. This is saved as testMenu.jsx in the Scripts > startup scripts folder.

P.S. I'm testing this in CS5.5 currently, but ideally this solution should work in CS3 and later.

 

#targetengine "myTestMenu"  
var myFolder = Folder(app.activeScript.path);
myFolder = myFolder.parent + '/Scripts Panel/';  
var menuItem1Handler = function( /*onInvoke*/ ){  app.doScript(File(myFolder + 'MyTest1.jsx'));};  
var menuItem2Handler = function( /*onInvoke*/ ){  app.doScript(File(myFolder + 'MyTest2.jsx'));};  
menuInstaller()
function menuInstaller() {  var menuItem1T = "My Menu Item 1",       menuItem2T = "My Menu Item 2",       menuT = "MyTestMenu",             subT = "Sub Menu",       subs = app.menus.item("$ID/Main").submenus, sma, mnu;  var refItem = app.menus.item("$ID/Main").submenus.item("$ID/&Layout");    subMenu1 = app.scriptMenuActions.item(menuItem1T);  if( subMenu1 == null ) {          subMenu2 = app.scriptMenuActions.add(menuItem1T);  }    subMenu2 = app.scriptMenuActions.item(menuItem2T);  if( subMenu2 == null ) {          subMenu2 = app.scriptMenuActions.add(menuItem2T);  }  subMenu2.eventListeners.add("onInvoke", menuItem2Handler);    mnu = subs.item(menuT);  if( mnu == null ) {            mnu = subs.add(menuT, LocationOptions.after, refItem);  }  mnu.menuItems.add(subMenu1);  mnu.menuSeparators.add();    subsSubs = app.menus.item( '$ID/Main' ).submenus.item( menuT ).submenus;  mnuSubMenu = subsSubs.item( subT );  if( mnuSubMenu == null ) {          mnuSubMenu = subsSubs.add( subT);  }    mnu.menuItems.add(subMenu2);}

Viewing all articles
Browse latest Browse all 15932

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>