Copy link to clipboard
Copied
Hi all,
I'm trying to add a menu item with an onInvoke event listener.
I'd like my menu to invoke a script using the doScript method.
However, when I run it, it doesn't create my menu item.
Any advice here?
#include "C:/Users/jcahill/AppData/Roaming/Adobe/InDesign/Version 12.0/en_GB/Scripts/Scripts Panel/import idml translations.jsx"
#targetengine "session"
var m = app.menus.item( "$ID/Main" ).submenus.item( "Import translations" );
m.isValid&&m.remove();
var addCustomMenu = (function () {
var customMenuAction = app.scriptMenuActions.add( "Choose IDML files" );
var customMenu = app.menus.item( "$ID/Main" ).submenus.item( "Import translations" );
var customMenuItem;
if ( !customMenu.isValid ) {
customMenu = app.menus.item( "$ID/Main" ).submenus.add( "Import translations" );
customMenuItem = customMenu.menuItems.item( "Choose IDML files" );
}
var u;
var f = function () {
app.doScript( "import idml translations.jsx", u,u,UndoModes.ENTIRE_SCRIPT, "Import IDML files" );
}
var el = customMenuAction.eventListeners.add( "onInvoke", f, false );
if ( !customMenuItem.isValid ) {
customMenu.menuItems.add( customMenuAction );
}
}());
Your code works just fine at my place with InDesign CS6 to 2017.
Only difference I might have is that your inclusion does throw an error that prevents the script to be further executed but in those case, you should be warned by a specific message.
Copy link to clipboard
Copied
Your code works just fine at my place with InDesign CS6 to 2017.
Only difference I might have is that your inclusion does throw an error that prevents the script to be further executed but in those case, you should be warned by a specific message.
Copy link to clipboard
Copied
Thanks Loic, in the end I just put everything in my included script inside a function, then added that function to the eventListener.
Thanks for the reply