Menus Enable/Disable (Built-in Menus)

Participant ,
Mar 07, 2018 Mar 07, 2018

Copy link to clipboard

Copied

Hi,

     We can invoke the menus using MenuActions.  How can i disable/enable InDesign's built-in menus using indesign javascript?

TOPICS
Scripting

Views

3.6K

Likes

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

Guide , Mar 19, 2018 Mar 19, 2018

(…) Can we disable (stop) the process of only export PDF from Export menu?

I think so. The ImportExportEvent object has a format property that should be useful to filter file format.

In the callback function (disableProcess), you could add a condition of the form:

if( ev.properties.format == … ) etc

@+

Marc

Likes

Translate

Translate
Guide ,
Mar 19, 2018 Mar 19, 2018

Copy link to clipboard

Copied

(…) Can we disable (stop) the process of only export PDF from Export menu?

I think so. The ImportExportEvent object has a format property that should be useful to filter file format.

In the callback function (disableProcess), you could add a condition of the form:

if( ev.properties.format == … ) etc

@+

Marc

Likes

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
Participant ,
Mar 26, 2018 Mar 26, 2018

Copy link to clipboard

Copied

HI,

    The below code stop the process of export pdf using event format beforeExport. But when i click the export menu (Adobe PDF Print) the below dialog appeared and then only process gets stop.  Can I skip this dialog??

      Similary for Adode PDF (Interactive).

     Can i use jsxbin file instead of jsx in startup script folder?? it will work without any issue??

Screen Shot 2018-03-27 at 9.47.01 AM.png

Code:

#targetengine "exportPDF"

main();

function main() {

    //var myApplicationEventListener = app.eventListeners.add("afterExport", disableExportOption, false);

    var myApplicationEventListener = app.eventListeners.add("beforeExport", disableExportOption, false);

}

function disableExportOption(evt) {

    if(evt.format == "Adobe PDF (Interactive)" || evt.format == "Adobe PDF (Print)")

    {

        alert("Don't Export PDF as Manual. Use Script to Export PDF!!");

        evt.stopPropagation();

        evt.preventDefault();

        return;

    }

}

Likes

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
Guide ,
Mar 27, 2018 Mar 27, 2018

Copy link to clipboard

Copied

Hi Sudha K,

As commented in the code at #20, the best solution would have been to listen to the submenu actions [High Quality Print], [PDF/X-1a:2001] and so on, using the beforeInvoke event. I tried this approach first, but it didn't work for me. So we seem to have no choice but to detect the beforeExport event, downstream. Alas, it only occurs once the user has validated the Export Adobe PDF dialog.

Maybe there is a way to hook that dialog, I don't know.

> Can i use jsxbin file instead of jsx in startup script folder?? it will work without any issue??

1. Compile the script without its #targetengine directive.

2. Open the jsxbin in an editor, remove line breaks and copy the entire string.

3. Create a jsx with:

#targetengine "<yourEngine>"

eval("<yourJsxBinString>");

@+

Marc

Likes

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
Participant ,
Mar 28, 2018 Mar 28, 2018

Copy link to clipboard

Copied

Hi,

     Thank you.... Its working...

Likes

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
Community Expert ,
Mar 19, 2018 Mar 19, 2018

Copy link to clipboard

Copied

Hi Sudha,

see into the properties of the event that goes into your handler function.

There is property event.fullName with the value of the file that will export.
You could check the suffix from that and react accordingly.

Regards;
Uwe

Likes

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
Community Expert ,
Mar 19, 2018 Mar 19, 2018

Copy link to clipboard

Copied

See also DOM documentation for the importExport event. From Jongware:

Adobe InDesign CS6 (8.0) Object Model JS: ImportExportEvent

Regards,
Uwe

Likes

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
Participant ,
Mar 19, 2018 Mar 19, 2018

Copy link to clipboard

Copied

Hi,

     thank you for the reply...

    

     I will check and get back...

Likes

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
Guide ,
Mar 19, 2018 Mar 19, 2018

Copy link to clipboard

Copied

You're absolutely right about the potential threat. I seem to remember we touched that topic before.

A script should NEVER use instructions of the form …eventListeners.everyItem().remove()—unless you are in the process of fixing a critical bug that totally breaks ID!

I plead guilty for removing event listeners in that way as part of testing my code without restarts, but I think it is a bug that the event listeners are shared. Target engines are supposed to be isolated, at the C++ side there is plenty code dedicated to engine awareness. EngineContext or RequestContext pointers passed all over the place. On the other hand, this opens interesting ways of inter-engine communication.

#targetengine Foo

app.eventListeners.add(Application.AFTER_ACTIVATE,dummy);

function dummy(){"Foo!"}

dummy.secret = "oops!";

$.writeln($.engineName);

$.writeln(app.eventListeners.length);

#targetengine main

var el = app.eventListeners.lastItem();

$.writeln($.engineName);

$.writeln(el.handler.toSource());

$.writeln(el.handler.secret);

Likes

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
Guide ,
Mar 27, 2018 Mar 27, 2018

Copy link to clipboard

Copied

Hi Dirk,

I plead guilty for removing event listeners in that way as part of testing my code without restarts, but I think it is a bug that the event listeners are shared. Target engines are supposed to be isolated, at the C++ side there is plenty code dedicated to engine awareness. EngineContext or RequestContext pointers passed all over the place. On the other hand, this opens interesting ways of inter-engine communication.

#targetengine Foo app.eventListeners.add(Application.AFTER_ACTIVATE,dummy); function dummy(){"Foo!"} dummy.secret = "oops!"; $.writeln($.engineName); $.writeln(app.eventListeners.length);

#targetengine main var el = app.eventListeners.lastItem(); $.writeln($.engineName); $.writeln(el.handler.toSource()); $.writeln(el.handler.secret);

Nice trick. You need to access the right eventListener though—and lastItem() is usually not a safe specifier 😉

Also, itemByName(myUniqueIdentifier) is not supported in CS4 (for eventListeners.)

So in absolute terms we either need a unique DOM id (which is not necessarily known from the co-script at hard-coding time), or some lookup mechanism throughout existing listeners and their associated handlers.

Question: What's your opinion about using $.setenv() and $.getenv() to share data across the session? I use that approach in IdExtenso, in particular in the Settings module. To your knowledge, is there any drawback with it?

Best,

Marc

Likes

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
Guide ,
Mar 27, 2018 Mar 27, 2018

Copy link to clipboard

Copied

Marc, of course you could add the event listener to some obscure object where nobody looks. Anyway it is a hack and I would not be surprised if the next garbage collection blows up straight into your face, or similar side effects.

Regarding $.getenv, that is for processes sharing string values with child processes. So if you launch InDesign from a shell script and want to pass a file name, that could be an option. Pick up the Unix user name. Also the opposite way, when you fork sub-processes from InDesign. I recently learned that Photoshop has app.system, maybe even File.execute would pass the environment. Better don't use it to store gigabytes, and the environment is shorter lived than app.insertLabel and friends. Also avoid variables that have special meanings, e.g. DYLD_LIBRARY_PATH.

Likes

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
Explorer ,
Jan 01, 2019 Jan 01, 2019

Copy link to clipboard

Copied

Hi, Can you please share the script property to disable below options in InDesign.

Screenshot.jpg

Likes

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
Participant ,
Jan 01, 2019 Jan 01, 2019

Copy link to clipboard

Copied

Hi,

     If we disable the visibility in an InDesign, the corresponding menu item is hidden inside the InDesign application.  Do you want to this ? or just disable the functionality of the menu item?

Likes

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
Explorer ,
Jan 01, 2019 Jan 01, 2019

Copy link to clipboard

Copied

LATEST

Hi, I want to hide the "Fill with Placeholder Text" in right click option.

Required.jpg

Likes

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
Guide ,
Mar 11, 2018 Mar 11, 2018

Copy link to clipboard

Copied

Here is another resource you may find interesting: Prevent executing menu items | IndiSnip [InDesign® Snippets]

So far as tutorials, if you download the Javascript SDK InDesign SDKs and tools | Adobe Developer Connection  there are some eventlistener tutorials that may assist you.

Likes

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
Participant ,
Mar 11, 2018 Mar 11, 2018

Copy link to clipboard

Copied

Thank you...

I will check the given links...

Likes

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