Skip to main content
Inspiring
March 8, 2018
Answered

Menus Enable/Disable (Built-in Menus)

  • March 8, 2018
  • 4 replies
  • 7935 views

Hi,

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

This topic has been closed for replies.
Correct answer Marc Autret

Hi,

     Thanks for your help...

     I need one more clarification, we can disable the menus functionality using event listener.  Can we disable (stop) the process of only export PDF from Export menu?

     Export menu have multiple options (html, idml, pdf etc..). Can we stop the process of specific file format of export??


(…) 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

4 replies

Colin Flashman
Community Expert
March 12, 2018

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.

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!
Sudha_KAuthor
Inspiring
March 12, 2018

Thank you...

I will check the given links...

Colin Flashman
Community Expert
March 9, 2018

Sudha K

Perhaps have a look at my video that features the startup script in question: Episode 19: Preflight overview and "enforcer" scripts - YouTube

If you want the startup script, please contact me via my website that is linked in the Youtube video. The script is free but I'm trying to gauge interest in the script at this stage.

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!
Sudha_KAuthor
Inspiring
March 9, 2018

Hi,

     I am trying the startup script using the below code.  But its throwing the attached warning.

#target indesign

#targetengine 'onOpen'

(function() {

  app.eventListeners.add("afterOpen", afterOpen);

  function afterOpen(myEvent) {   

        var doc = app.activeDocument;

        app.menuActions.itemByName ( "$ID/Export..." ).enabled = false;

        alert(doc.name);       

   }

}())

     Is it possible to disable indesign's menu item "Export" and "Print"?

Sudha_KAuthor
Inspiring
March 13, 2018

Hi,

you could test your script without being a start-up script first.

Best would be to include a "toggle" functionality:

Start the script: The event listeners will be added.

Start the script a second time: The event listeners will be removed.

Include alert messages.

How would that work? Identify your event listeners by name. For example:

( function()

{

#targetengine "bestChooseUniqueNameHere"

var myEventListenerName = "givenName";

var myEventListener = app.menuActions.itemByID(39938).eventListeners.itemByName( myEventListenerName );

if( myEventListener.isValid ){ myEventListener.remove(); alert("Listener removed."); return } // End script here!

myEventListener = app.menuActions.itemByID(39938).addEventListener("beforeInvoke", disableProcess);

myEventListener.name = myEventListenerName ;

alert("Listener added!");

// …

}() )

So you see, you can give event listeners names.

Look into this: Adobe InDesign CS6 (8.0) Object Model JS: EventListener

Otherwise you always have to restart InDesign if something goes wrong.
Or you need a second script to remove it…

app.menuActions.itemByID(39938).eventListeners.everyItem().remove();

Regards,
Uwe


HI,

     I run the code given above.  It gives the alert for "Listener added" but did not give any alert for "Listener removed". I quit the application and run the script.

     My doubt is, startup script start to work when indesign is on.  When application is quit, event listener wont get removed??

     Scripts all will load when app is on.. Then how to call it as second script?

     Can I use like this...

#target indesign

#targetengine 'onOpen'

var elPackageName = "PackageEventListner";

var elPackage = app.menuActions.itemByID(39938).eventListeners.itemByName( elPackageName );

if(elPackage.isValid)

{

    elPackage.remove();

}

var elExportName = "ExportEventListner";

var elExport = app.menuActions.itemByID(39938).eventListeners.itemByName( elExportName );

if(elExport.isValid)

{

    elExport.remove();

}

var elExportToPDFName = "PackageEventListner";

var elExportToPDF = app.menuActions.itemByID(39938).eventListeners.itemByName( elExportToPDFName );

if(elExportToPDF.isValid)

{

    elExportToPDF.remove();

}

var elPackage = app.menuActions.itemByID (39938).addEventListener ("beforeInvoke", disableProcess);      // Package

var elExport =  app.menuActions.itemByID (113411).addEventListener ("beforeInvoke", disableProcess);     // Export...

var elExportToPDF =  app.menuActions.itemByID (108046).addEventListener ("beforeInvoke", disableProcess);     // Export To PDF

function disableProcess(evt)

    evt.stopPropagation();

    evt.preventDefault();

    return;

}

Colin Flashman
Community Expert
March 8, 2018

I'd use Laubender's suggestion with the event listener. I have a startup script that prevents a user from being able to print or export a PDF unless the preflight panel uses a specific preflight profile and has zero issues. The script listens for an Export or Print request and then calls the checkJob function to perform the rest of the script:

var  beforeExport = app.menuActions.itemByName ( "$ID/Export..." ).addEventListener ( "beforeInvoke", checkJob ); 

var  beforePrint = app.menuActions.itemByName ( "$ID/Print..." ).addEventListener ( "beforeInvoke", checkJob );            

The checkJob function runs just like any other function, but note the "preventDefault()" and "stopPropagation" portions:

function checkJob(myEvent){   

//other stuff goes here to make the script do what I want
myEvent.preventDefault(); 

myEvent.stopPropagation(); 

exit(0);}

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!
Community Expert
March 8, 2018

Hi Colin,

yes. And there is another thing what can be done with menus. One could use merhod remove() on them.
But then the problem is to add them to the application again without doing a new install of InDesign.
I would never try that on purpose… Just wanted to add this option to the repertoire of harsh actions ;-)

Regards,
Uwe

Colin Flashman
Community Expert
March 8, 2018

G'day Uwe

I agree, I would not use the remove() method either... that's a rabbit-hole that is NOT worth exploring! I like the event listener option because it's easy to remove a startup script if it's causing too much grief, whereas restoring removed menu items (as I understand it) would be done through either a reinstall or trashing preferences, two things I dislike doing.

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!
Community Expert
March 8, 2018

Hi Sudha,

just ask yourself how you would accomplish that with a user interface action?

That's under Edit/Menus… where you can restrict the view on a menu.

Never tried to access this by scripting.

Another way is to add an event listener to the menu that listens at the beforeDisplay event and do something—maybe invoking something else?—to prevent that menu from executing. Just a vague idea…

Regards,
Uwe