• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

adding a menu action

Engaged ,
Jan 03, 2017 Jan 03, 2017

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 );
       
        }
   
    }());
  

TOPICS
Scripting

Views

802

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Jan 04, 2017 Jan 04, 2017

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.

Votes

Translate

Translate
People's Champ ,
Jan 04, 2017 Jan 04, 2017

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 05, 2017 Jan 05, 2017

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines