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