2

I can't invoke menu items in scripts. For example:

app.menuActions.item("$ID/Override All Master Page Items").invoke;
app.menuActions.item("$Override All Master Page Items").invoke;
app.menuActions.itemByID(6164).invoke;

app.menuActions.item("$ID/Select All").invoke;
app.menuActions.item("Select All").invoke;
app.menuActions.itemByID(276).invoke; 

alert("Done");

does nothing except show the alert at the end.

I've checked that the IDs are valid and the action name is unique (at least for "Override All Master Page Items") with:

myMenuActions = app.menuActions.itemByName("Override All Master Page Items").getElements();  
for (var i = 0; i < myMenuActions.length; i++) {  
          alert(myMenuActions[i].area + " " + myMenuActions[i].id);  
}

I've also read through Kaysan's guide to scripting menu items in InDesign but all to no avail.

Any idea what's going wrong? (I'd prefer to reference menu items by locale-independent names rather than IDs but I'd settle for anything at this stage.)

I'm running InDesign CC 2014 on Windows 10, and I'm using Notepad++ to edit scripts, not the Adobe ExtendScript environment, just in case that should be relevant. Thanks in advance!

tmgr
  • 123
  • 1
  • 7
  • As an IDE the extendscript toolkit leaves a bit to be desired, but it does allow you to debug scripts. Consider running the script from ESTK with breakpoints set so that you can investigate what is actually going on. – stib Oct 23 '16 at 23:30

2 Answers2

4

You need to add () to .invoke as it's a method.

So it should be:

app.menuActions.item("$ID/Override All Master Page Items").invoke()

Hope that helps

John

johnt
  • 56
  • 3
0

Unfotunately sometimes it trows an error no matter what. Even if you put brakets after invoke method, etc.

Here is an example:

app.menuActions.item("$ID/High Quality Display").invoke();

This way I'm getting the error message:

enter image description here

But it does the work anyway: toggles a display in the 'High Quality' preview mode. So I just put the command into the try + catch(e) container:

try { app.menuActions.item("$ID/High Quality Display").invoke() } catch(e) {}

And here we go. It shows no error messages and works fine.

Alternatively I can use itemByID instead:

app.menuActions.itemByID(78348).invoke();

It does the same thing with no error.

And some actions work only when respective panels are visible. For example you can't invoke Edit Original action if the panel "Links" is hidden.

Yuri Khristich
  • 13,448
  • 2
  • 8
  • 23