Unable to activate menu options within InDesign CC script

I am facing an issue with invoking menu items in scripts. Here is an 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");

Despite the code above, only the alert message is displayed at the end.

I have confirmed that the IDs are correct and the action name is unique (at least for "Override All Master Page Items") by running:

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 have also consulted Kaysan's guide to scripting menu items in InDesign, but I still haven't found a solution.

Any suggestions on what might be causing this issue? (I would prefer to use locale-independent names to reference menu items instead of IDs, but I am open to any solution at this point.)

My setup includes InDesign CC 2014 on Windows 10, and I am using Notepad++ to edit scripts, not the Adobe ExtendScript environment. Thank you in advance!

Answer №1

Remember to include the parentheses () after .invoke since it is a method.

Therefore, the correct syntax is:

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

Let me know if you have any questions.

- Jane

Answer №2

Unfortunately, there are times when it throws an error no matter what. Even if you add brackets after the invoke method, etc.

Here's an illustration:

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

When I do this, I receive an error message:

https://i.sstatic.net/BRHRL.png

However, it still accomplishes the task: switching a display in the 'High Quality' preview mode. So, I simply enclose the command in a try + catch(e) block:

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

This resolves the issue. There are no error messages displayed and it functions correctly.

Alternatively, I could utilize itemByID instead:

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

This achieves the same outcome without any errors.

Additionally, certain actions only work when their respective panels are visible. For instance, you cannot invoke the Edit Original action if the "Links" panel is hidden.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with printing error messages for JavaScript form validation

I have implemented the following code for a form to handle validation and display errors below the fields when they occur: <!DOCTYPE html> <html> <head> <style type="text/css"> .errorcss { background-color: yellow; color:re ...

How can I achieve a similar functionality to array_unique() using jQuery?

When I select values from a dropdown, they are stored as an array like ["1","2","3"] Upon each change, the code below is executed to generate a new array based on the selected values: $('#event-courses-type').on('change', function(){ ...

Retrieve the output from PHP in JSON format and then utilize jQuery to parse it

I am currently working on a jQuery function $.post(file.php), where the data is being sent to "file.php" and returned in JSON format using json_encode(). Although I am able to successfully retrieve the result, I am unsure how to separate the individual i ...

What is the best way to ensure that my grid remains contained within its designated area?

I need to incorporate a grid of 16x16 or 64x64 into my layout without it overflowing. I'm considering using flexbox, but unsure of the implementation process. My goal is to have the grid resize based on the container size rather than exceeding its bou ...

Embedding a stylesheet into an HTML document can be done automatically

Currently, I am working on creating standalone error pages (404/503) as individual HTML files. My server-side setup involves Node.js, but these specific files will be hosted directly in Nginx. One of the challenges I am facing is automatically including a ...

AngularJS - Utilizing Google's Place Autocomplete API Key

Recently, I started digging into Google's APIs and attempting to integrate the Places Autocomplete API with Angular. Although I'm fairly new to autocomplete features in general, I haven't included the jQuery library in my project yet. I&apos ...

Differentiate input elements with custom styling

I'm experiencing an issue while trying to style a specific form field in Angular 7. The style doesn't seem to be applying properly. Below is my form structure: <ul> <li> <mat-form-field *ngIf="number"> <input ma ...

I'm receiving identical results from findOne even when using different IDs

I am currently working on creating a new array of products based on a list of different Ids. However, I have encountered an issue where the same product is being returned for all Ids when using the findOne() method. let wishpro = ['632a5e5rtybdaaf ...

Avoiding line breaks when submitting data through Ajax calls is achievable by using the `.val` method

I've come across multiple articles discussing ways to add line breaks to the .val in jQuery, but unfortunately none of them have worked for me. I attempted using the recommended workaround provided by jQuery: $.valHooks.textarea = { get: function( ...

How come I am unable to scroll beyond my parallax section unless I move the mouse first?

Currently, I am working on a webpage that includes a Parallax landing image. In order for the Parallax effect to function properly, the image has a greater height, requiring users to scroll down. This leads to the appearance of a second scrollbar specifica ...

Invoke a function only once in a Node.js application

What is the best way to execute a method only once when starting a node application? I am considering placing it in server.js, the executable file of my application, but I'm unsure if this is the correct approach. Are there any other options I should ...

Tips for retrieving an input value following a DOM insertion

Developing a function to inject HTML into the DOM following an AJAX call like this: The function for injecting HTML $.ajax({ type: "POST", url: base_url + "main/GetTheLastSeq" }) .done(function( msg1 ) { ...

Customizing next.js _error page with i18n localization

Looking to create a customized error page for my Next.js project. I've been using the getServerSideProps method to localize my other pages, but I'm running into issues with translating strings on the _error page. I attempted to use the getStaticP ...

Simple method to retrieve unordered list identifiers as an array using PHP

Currently, I am working with an unordered list where I am using DB ids as the list-item ids. When the Submit button is pressed, I want to present all the ID's of my list items as an Array in PHP. I am still learning JavaScript and although there are s ...

What is the significance of declaring a variable outside of a JavaScript function? (Regarding jQuery and #anchor)

In my jQuery function, I needed to determine the current #anchor of the page. To achieve this, I utilized the jQuery URL Parser plugin. $.fn.vtabs = function() { alert("The current anchor is "+$.url.attr('anchor')); } Initially, the code c ...

Attempting to manipulate the selected tab material using a custom directive with two-way data binding

I've been struggling to change the tab using code and can't seem to figure out what's causing the error. It works fine when I use the controller to change the variable, but when trying to bind it through a directive, it breaks. var app = an ...

Displaying the total count of slides available on the webpage

Check out the custom slider I created on this codepen page: http://codepen.io/anon/pen/NqQpjG I have added an additional feature that tracks the total number of slides that have been moved. For instance, if there are a total of 8 slides, the initial va ...

Is it possible to dynamically adjust div height using on resize event?

In my current setup, I have two separate divs on the left and right sides. The issue arises when the height of the left div exceeds the height of the right div. In such cases, the function adjusts the heights to be equal and hides any excess text in the le ...

Application experiencing server error when updating MongoDB data

I have encountered an issue while trying to update/modify data that has already been uploaded in a reactjs project using mongoDB as the database. Whenever I attempt to update the data, an error is displayed. How can this problem be resolved? https://i.sta ...

What is the method for reaching a service in a different feature module?

Currently, I am utilizing Angular 2/4 and have organized my code into feature modules. For instance, I have a Building Module and a Client Module. https://i.stack.imgur.com/LvmkU.png The same structure applies to my Client Feature Module as well. Now, i ...