I'm making some Adobe Bridge (CS 5.1) plugins.
My problem is that I cannot figure out how to ensure that their respective menu items will be greyed out unless the user has selected valid items for the script.
I can reach the desired state by coding something like
function greyOutMenu () {
var doc = application.document;
var these = [];
these = doc.selections;
menuItem.enabled = true;
if ( these.length < 1 ) {
menuItem.enabled = false;
return;
}
for ( var i in these ) {
if ( these[i] /* is invalid */ ) { menuItem.enabled = false;
return;
}
}
but how do I get this check to run directly when the menu is opened? If I use
myMenu.onSelect = greyOutMenu();
It just runs the check on startup instead of when the menu is opened!
Okay, I figured out what was wrong. I have changed it to...
function greyOutMenu () {
var doc = app.document;
var here = doc.presentationPath;
var thisFolder = Folder ( here );
if ( decodeURI ( thisFolder.name ) === "correct folder name" ) { menuItem.enabled = true; }
else { menuItem.enabled = false; }
if (!app.document.selectionsLength > 0 ) { menuItem.enabled = false; }
}
menuItem.onDisplay = greyOutMenu;
I could have sworn that I had already tried menuItem.onDisplay
, but I must have made a syntax error.
Also, In my case it is enough to be in the right folder and have something selected, as the files are added directly by a camera. More complex checks are instead added to the function itself, to prevent stuttering every time the menu is opened.