Some very basic pointers needed

General Discussion of Scripting for Adobe Bridge

Moderators: Tom, Kukurykus

miked

Some very basic pointers needed

Post by miked »

Hi there

I'm wondering if someone can point me to some basic info on scripting with bridge. I am a fairly accomplished PS scripter, but I can make no sense of doing things in Bridge...I can't even figure out where to save scripts, or how to make them show up.

The documentation is, of course, total suckage. Google revealed nothing as well. And it looks like this forum doesn't get much traffic either, but I thought I'd ask. Any takers?

...Mike
Patrick

Some very basic pointers needed

Post by Patrick »

Bridge scripts are loaded very differently than Photoshop. As you know, Photoshop has a script menu that allows you to brows to your scripts whenever you want to use one. Bridge has no interface like this, all it has is a folder you place scripts in, and it executes them all every time Bridge is launched. To find this folder, do:

Edit > Preferences > Reveal Scripts

Now is the part that is cooler than how Photoshop handles scripts IMO. Since scripts only get loaded on Bridge launch, what you need to do is have your scripts add menu's to the Bridge interface to allow you to access them whenever you want. Bridge allows you to add items to any menu, add your own menu, or add things to the right click menu.

Here is a example of a script that adds a new menu with a menu item, hopefully it will help make sense of what I am talking about.

Code: Select allfunction main() {
   if( BridgeTalk.appName == "bridge" ) // only works with Bridge
   {
      
      
      
      /* create main menu elements*/
      newMenu = new MenuElement( "menu", "Patrick\'s Tools", "after Help", "myMenu" );
      floatCommand = new MenuElement( "command", "Floating menu", "at the end of myMenu","myAlert" );
      
      
      
      /* floating menu function */      
      floatCommand.onSelect = function () {
         var dlg = new Window(
            "palette{text:'Script Interface',bounds:[100,100,630,570],\
            pan0:Panel{bounds:[10,10,520,460] , text:'File Info' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},\
            button0:Button{bounds:[100,410,200,430] , text:'Refresh' },\
            statictext0:StaticText{bounds:[10,20,60,37] , text:'Name:' ,properties:{scrolling:undefined,multiline:undefined}},\
            statictext1:StaticText{bounds:[10,40,60,57] , text:'Type:' ,properties:{scrolling:undefined,multiline:undefined}},\
            edittext0:StaticText{bounds:[70,20,500,37] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},\
            edittext1:StaticText{bounds:[70,40,500,57] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}}\
            }\
            };"
         );
         
         // starting file info, if file selected
         if (app.document.selections.length == 1) {
            dlg.pan0.edittext0.text = app.document.selections[0].path;
            dlg.pan0.edittext1.text = app.document.selections[0].type;
         };
         
         dlg.pan0.button0.onClick = function(m) {
            if ( app.document.selections.length == 0) {
               // if nothing selected
               dlg.pan0.edittext0.text = "<no file selected>";
               dlg.pan0.edittext1.text = "<no file selected>";
            } else if ( app.document.selections.length == 1 ) {
               // if one file selected
               var tn = app.document.selections[0];
               dlg.pan0.edittext0.text = tn.path;
               dlg.pan0.edittext1.text = tn.type;
            } else {
               // if more than one selected
               dlg.pan0.edittext0.text = "<too many files selected>";
               dlg.pan0.edittext1.text = "<too many files selected>";
            }; // end if
         }; // end onClick
         
         
         dlg.modal = true;
         dlg.active = true;
         dlg.center();
         dlg.show();
      }; // end onSelected
      
      
   }; // end if
}; // end main()



// run script
main();

Hope this helps,

Patrick
miked

Some very basic pointers needed

Post by miked »

Thanks Patrick
bjorke

Some very basic pointers needed

Post by bjorke »

Can't you just navigate to the script in the usual bridge browser window and double-click?

(of course, this precludes making a script that does anything useful with the current selection)
xbytor

Some very basic pointers needed

Post by xbytor »

bjorke wrote:Can't you just navigate to the script in the usual bridge browser window and double-click?
[/bjorke]

Yes. You should have
Code: Select all#target bridge

as the first line in your script to work well.

(of course, this precludes making a script that does anything useful with the current selection)

It shouldn't. I frequently run Bridge scripts from within ESTK all the time. It greatly simplifies debugging. Of course, however, I don't typically do anything with registering menu items, etc...

-X
Patrick

Some very basic pointers needed

Post by Patrick »

xbytor wrote:I frequently run Bridge scripts from within ESTK all the time. It greatly simplifies debugging. Of course, however, I don't typically do anything with registering menu items, etc...

All the scripts I have made for Bridge used either menu items or palettes, and I must say debugging in ESTK was nightmarish. Every time I would make a edit and like to reload the script, I would have to restart Bridge. If I didn't I would get multiple menu items that look identical and would have no way of figuring out which was the most current.

Patrick
xbytor

Some very basic pointers needed

Post by xbytor »

Patrick wrote:All the scripts I have made for Bridge used either menu items or palettes, and I must say debugging in ESTK was nightmarish.


Then don't do that Seriously, unless you are really testing the menu code, have a separate test function that you call at the end of your script.

Also, absolutely do not have any global variables or functions _except_ for the one that controls your script.

For instance, if you have a script that generates some CSV files based on metadata, etc... you would have one global symbol like this:

Code: Select allGenerateCSV = function(){};

Hang everything off that. It's a cheap and easy way to do namespaces in JS (if you know what those are).

Globlals and functions would be like this:
Code: Select allGenerateCSV.DEFAULT_TIMEOUT = 10; // seconds

GenerateCSV.noUI_test = function() {
   // code for testing this script without the UI goes in here.
};


Every time I would make a edit and like to reload the script, I would have to restart Bridge. If I didn't I would get multiple menu items that look identical and would have no way of figuring out which was the most current.

If you do like I describe above, every time you run the script, you create a new GenerateCSV object, which means that all of your old code 'magically' disappears. But this also means that if you previously added any menu items, etc... they will still be there. You don't need to add duplicate copies of your menu item code if it hasn't change. Your old menu item code could (if constructed correctly) call your reloaded code.

Bridge's interpreters are persistent across invocations (for good or bad) but you can fortunately create your on interpreter sessions. That, however, is virgin territory for me.