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"?

Community Expert
March 19, 2018

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??


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

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