• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to create a Context Menu submenu?

New Here ,
Sep 21, 2005 Sep 21, 2005

Copy link to clipboard

Copied

I am trying to create a submenu which lists scripts in the content window - Does anyone know how to do this?

This works:

if (MenuElement.find ('Thumbnail/tscript') == null) var ah_ScriptsContext = new MenuElement( "command", "Scripts", "at the end of Thumbnail", "tscript");

But the submenu does not work:

var ah_runScriptImRnContext = new MenuElement("menu","AH Image Rename","at the end of Thumbnail/tscript");

I've tried various combinations of 'menu' / 'command' and everything else I can think of, so far no go.

Andrew
TOPICS
Scripting

Views

1.3K

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
New Here ,
Sep 21, 2005 Sep 21, 2005

Copy link to clipboard

Copied

I'm not sure I quite understand exactly what you are trying to do, but here's a code snippet from a test app of mine that creates a new top level menu and adds one menu item to that menu.

var menu = MenuElement.find("testMenuID");
if (menu == null)
{
// add a menu item
var testMenu = new MenuElement("menu", "Test", "before Help", "testMenuID");
var cmd1 = new MenuElement("command", "Test #1 - Array Mods", "at the end of testMenuID", "test1ID");
cmd1.onSelect = TestFunc_ArrayMods;
}

--John

Votes

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
New Here ,
Sep 21, 2005 Sep 21, 2005

Copy link to clipboard

Copied

Hi John, thanks for the reply

That's basically what I want but with a context menu instead.

Right click a thumbnail in the content pane, and you see the 'Labels' option, which if clicked gives you various individual label options. I want to create an equivalent Scripts option in the same context menu (I can do that) which has individual script options within it (haven't managed to do that for a context menu so far, can do it for a main menu).

Andrew

Votes

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
New Here ,
Sep 21, 2005 Sep 21, 2005

Copy link to clipboard

Copied

I haven't tried this myself, but it looks like you are using the wrong menu type (first parameter when creating the MenuElement). Your first MenuElement is type "command" when I think it should be type "menu". That is probably why your sub-menu won't show up.

Votes

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
New Here ,
Sep 22, 2005 Sep 22, 2005

Copy link to clipboard

Copied

I tried both, neither worked.

Andrew

Votes

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 Beginner ,
Sep 22, 2005 Sep 22, 2005

Copy link to clipboard

Copied

Here ya go, Andrew:

Bob
Adobe WAS Scripting

#target bridge

ContextDemo = {};

ContextDemo.handler = function( menu ) {
alert( menu.text );
}
try {
MenuElement.create( "menu", "Menu", "at the end of Thumbnail", "cMenu" );
ContextDemo.m1 = MenuElement.create( "command", "Command 1", "at the end of cMenu", "cMenu/sub1" );
ContextDemo.m1.onSelect = ContextDemo.handler;
ContextDemo.m2 = MenuElement.create( "command", "Command 2", "at the end of cMenu", "cMenu/sub2" );
ContextDemo.m2.onSelect = ContextDemo.handler;
} catch ( e ) {
}

// now let's get tricky
// disabling a script generated context menu makes it disappear from the context menu

SelectExample = {}
SelectExample.menuSelected = function() {
alert( "You selected " + app.document.selections[ 0 ].name );
}
SelectExample.menu = undefined;
SelectExample.onSelectHandler = function( event ) {
if ( event.object.constructor.name == "Thumbnail" ) {
if ( event.type == "select" ) {
// event.object is the Thumbnail object that was selected
if ( event.object.isFileType( "jpg,jpeg,psd,tif,tiff" ) ) { // enable the menu for these files with these extensions only
try {
if ( !isValidReference( SelectExample.menu ) ) {
SelectExample.menu = MenuElement.create( "command", "MyCommand", "at the end of Thumbnail", "myMenuID" );
SelectExample.menu.onSelect = SelectExample.menuSelected;
} else {
SelectExample.menu.enabled = true;
}
} catch ( e ) {
}
} else {
try {
SelectExample.menu.enabled = false;
} catch ( e ) {
}
}
return { handled:true }; // tells Bridge event was handled
}
}
return { handled:false }; // tells Bridge event wasn't handled and
//to continue through the handler array
}
app.eventHandlers.push( { handler: SelectExample.onSelectHandler } );

Votes

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
Enthusiast ,
May 27, 2013 May 27, 2013

Copy link to clipboard

Copied

Hi Robert

I was testing this, but now on Bridge CS6 (windows7), it works ok only with 1 error:

there is no more .isFileType( )

event.object.isFileType( "jpg,jpeg,psd,tif,tiff" )

on Bridge CS6 (and CS5)

How could i detect if it is a CR2 or JPG, or even a Folder? on a event select Thumbnail?

If it is possible, I could add conditional subMenus. That should be great!

If you want, I'll put this question on a new post.

Votes

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
Valorous Hero ,
May 27, 2013 May 27, 2013

Copy link to clipboard

Copied

This is an 8 year old thread!

Some of these functions are from Bob's  WasScriptLibrary.jsx where you will find isFileType();

You will need to find a copy of this library.

Votes

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
Enthusiast ,
May 27, 2013 May 27, 2013

Copy link to clipboard

Copied

LATEST

Thanks, I found it here:

http://creativescripting.net/freeStuff/WasScriptLibrary.jsx.zip

I'm realizing that bridge scripting with 8 years old is the only that can really help me develop even more SDK Snp code.

Many things that could be done in 8 years I cuold not find unless this.

I talking about subMenus on the Folder panellete ( I did manage to have them) and I hope with WasScriptLibrary I will hopefully manage to have conditional subMenus on the Content  panellete depending on the kind of file/folder.

This is a must have for me and I think it is a shame that it is not more developed after 8 years.

That should boost many companies productivity!

It is a shame I'm not a guru on proggramming 😞 but I'm patient and very revolutionary (in the good sense) 🙂

Votes

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
New Here ,
Sep 22, 2005 Sep 22, 2005

Copy link to clipboard

Copied

Hi Bob, thanks for that. I like the idea of presenting menu items on the basis of what is selected but how does it deal with multiple selections some of which belong and others which do not - I guess if any do not belong to the accepted extensions then the item should not appear in the menu.

Andrew

Votes

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 Beginner ,
Sep 22, 2005 Sep 22, 2005

Copy link to clipboard

Copied

That's one of those opinion things.

IMHO if all files do not satisfy the requirements then you must do one of 2 things:

Disable - so the action can't happen
Warn - (perhaps with a do not show again checkbox) that some of the files can not be processed.

getBridgeFiles does the warning thing (with the checkbox).

Bob
Adobe WAS Scripting

Votes

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