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

Exploring and Exploiting the Bridge Libraries

Community Beginner ,
Jun 28, 2005 Jun 28, 2005
One of the things we did when we developed the Bridge Workflow Automation Scripts, was create a set of libraries to make bridge scripting easier and more productive.

The libraries are AdobeLibrary1.jsx and AdobeLibrary2.jsx. There is an AdobeLibrary3.jsx, but it's primarily patches for the other two.

Over the next few weeks, I am going to post some messages about those libraries to help get folks started bridge scripting.

First up are some file handling utilities.

getBridgeThumbnails and getBridgeFiles are two library functions that return the selected (in Bridge) Thumbnail objects or File objects. getBridgeFiles takes the output from getBridgeThumbnails and converts them to File objects. These functions also ensure that any Version Cue files that were selected are up to date on the local file system prior to returning the selected objects.

The definition is:

getBridgeThumbnails = function( mask, getFolderChildren, filesOnly, firstOnly )

Where:

mask is a comma delimited list of file extensions or Mac file type strings. The function will only return Thumbnails that point to files of these types. It defaults to no mask, which will return everything. If the user selected Thumbnails that are not included in the mask, the user will be warned by an alert dialog (the user has the ability to opt not to be warned again).

getFolderChildren is a boolean. Set to true, it will return the first level children of any selected folder. The concept is that if a user selects a folder in bridge, they can operate the files in that folder. It defaults to true.

filesOnly is a boolean. Set to true, it will return only files, no folders. It defaults to false.

firstOnly is a boolean. Set to true, it returns only the first valid file found. This is useful when you are attempting to do an example of the result of one of the selected files. It defaults to false.

One more thing: If the user has a document open in bridge, but has not selected anything, it will assume the entire contents of the document are desired. It will flip up a warning dialog if this is the case (the user can opt to not be warned again).

We also extended the File Object in bridge (not the point apps) to do the file filtering for us. Part of that was the creation of a number of standard masks.

TYPES.PHOTOSHOP
TYPES.PHOTOSHOP_OPENABLE
etc.

var thumbs = getBridgeThumbnails( TYPES.PHOTOSHOP_OPENABLE, true, true );
for ( var i = 0; i < thumbs.length; i++ ) {
thumb = thumbs[ i ];
// do something with the selected thumbnail
}
TOPICS
Scripting
958
Translate
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 Expert ,
Jun 29, 2005 Jun 29, 2005
Robert

This sort of posting is just what's needed and can I encourage you to post more like this, and to continue using less techy language? IMO the Bridge scripting documentation is a bit on the obscure side!

I'm sure a few of us are struggling to join up the dots. So for instance, where are these libraries? I tracked them down in the Import Camera Script at the Exchange. Where do they go? The pdf file with that script says stick them in the StartupScripts folder - which one can get to via Bridge's Preferences dialog.

The line "// do something with the selected thumbnail" could also point out that the thumb object is a thumbnail. Ah, it looks like we can get to metadata with:

md= thumb.metadata;
Window.alert (md.author)

I'm sure there's a lot that's very good in Bridge scripting (though I would still like to see it with VB as many users will want to integrate with non Creative Suite products/applications) but it's proving a bit hard to get at.

As I've commented before, what's the point of making the pdf documentation read only? How often do you rekey something and find you misread a "{" and a "("? Users need to cut and paste the (very few) example scripts.

More of the same please.

John
Translate
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 ,
Jun 29, 2005 Jun 29, 2005
John,

Thanks.

I'll try to get some basic examples up here too. I think the docs on Exchange were replaced with a non-read only set. Try downloading them again.

Next Topic: The basic Bridge Scripting Paradigm

Bridge being what it is, the typical usage of a script is to select a set of files, then select a menu item to perform some magic on the selected files.

Scripts, therefore, typically need to create a MenuElement at startup, and then wait patiently for the user to call them.

There are 2 ways scripts get loaded. The first is by placing them in the startup scripts folder. The best way to find the startup scripts folder is to click the button in Preferences.

The other way is via Adobe ScriptManager. Script Manager is shipped with the full Creative Suite. It does what it says, pretty much. Provides a way to control what scripts load at startup and what don't. With ScriptManager installed (in startup scripts), it automatically loads scripts in the Workflow Automation Scritps folder (child of startup scripts for the full CS2 installation) and one other folder that is settable by the user.

The Script Manager also has some nice to have features for scripters. When a user selects a script, the Script Manager displays information provided by the scripter. The information includes stuff like the script's name, description, help, author, website, etc. As a scripter, you should always write your scripts assuming the Script Manager is present and loading your script.

To do this, the minimum script template is:

// first is a target directive - tells the extendscript engine that
// this script should be loaded into bridge. Makes it so that if a
// user opens the script in Bridge, it will load it rather than
// display the raw script in the ESTK

#target bridge

// next - all point products attempt to load all scripts in the
// startup scripts folder, if your's is bridge-only, make sure it
// only loads in bridge by wrapping everything in a condition like
// this

if ( BridgeTalk.appName == "bridge" ) {

// always make a namespace object for your script. Make it something
// that will not likely be something someone else might use. This
// avoids possible name collisions between scripts

myScript = {}; // namespace object for this script

// next ditty is for the Script Manager
try {
myScript.scriptInfo = new ScriptManager.ScriptInfo();
myScript.scriptInfo.set( "name", "My Script" );
myScript.scriptInfo.set( "description", "A Cool Script" );
myScript.scriptInfo.set( "help", "Help text" );
myScript.scriptInfo.set( "author", "Your Name" );
myScript.scriptInfo.set( "company", "Your Company" );
myScript.scriptInfo.set( "copyright", "It's mine and you can't have it );
myScript.scriptInfo.set( "version", "1.0" );
myScript.scriptInfo.set( "date", "06-27-2005" );
myScript.scriptInfo.set( "website", "http://www.adobe.com" );
} catch ( e ) {
}

// Your Script Goes HERE.

myScript.ui = function( menu ) {
// this function puts up any UI your script needs, then executes
// the script
}

// create your menu
var menu = MenuElement.create( "command", "My Menu", "at the end of Tools", "tools/myScript" );
menu.onSelect = myScript.ui;

// the last thing for the Script Manager - after your script has
// loaded, send the script info object to it.

try {
ScriptManager.reportLoading( myScript.scriptInfo );
} catch ( e ) {
}

} // closing brace for the if (appName == bridge) condition
Translate
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 Expert ,
Jun 29, 2005 Jun 29, 2005
In fact I was so interested by your initial post that I then spent a couple of hours putting together a script to export metadata to a text file

John
Translate
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 Expert ,
Jun 29, 2005 Jun 29, 2005
In fact I was so interested by your initial post that I then spent a couple of hours putting together a script to export metadata to a text file which included a menu.

John
Translate
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 ,
Jun 29, 2005 Jun 29, 2005
Well, thank you again, and congrats the script.

Looks "worky" to me!

Couple more tips:

Use MenuElement.create() instead of instantiating a new MenuElement with "new". MenuElement.create() prevents the duplication of menu's and collisions of menu id's.

and

Thumbnails are initialized in an asynchronous process. This isn't a problem when you're working with Bridge UI, but can cause problems when you are scripting.

The scripts execute so quickly that the initialization sometimes doesn't fully complete by the time you call the metadata object. That will cause the metdata calls to fail. You'll get a metadata object, but it won't be fully initialized, and will not return values until it is.

Way too late in the game to make the documentation, we added:

Thumbnail.synchronousMetadata

as a way to get a fully initialized metadata object.

In general, use this instead of the documented metadata property.

The script looks good!

Bob
Adobe Workflow Scripting
Translate
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 Expert ,
Jun 29, 2005 Jun 29, 2005
Thanks. I'll look at those methods. I had noticed some missing values at times - maybe that was the initialisation issue you mentioned.

I think I read somewhere that you planned to write a script to export metadata. Mine deals with a specific issue I have, though it can easily get other metadata.

One question - when I edit the script, I seem to have to close and reopen Bridge to refresh the menu/script. Is there a way to avoid this?

John
Translate
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 ,
Jun 29, 2005 Jun 29, 2005
If you have the ScriptManager (comes with the suite), you can open it, select the script, click the load on startup button twice.

If you don't, you can navigate to the script in bridge and "open it". I typically keep a pointer to startup scripts in my Favorites to make this easier.

It'd also be pretty easy to write a script that reads the contents of the startup scripts folder, creates a menu for each script file, selecting the menu reloads the script. You would either read the script file and execute an eval() on it, or create a thumbnail object from the file and use Thumbnail.open() - but this only works if there's a #target directive in the script. Wish I had the time to write handly stuff like this.

We did write an export metadata script. It's fairly involved in that it allows you to select any of data elements from all of the standard XMP schemas for export to CSV. Lots of UI, once you have an export set up, you can save it (and name it) for future use.

It's posted on the ASN site as an example. You have to sign up for the developer's program to get access. There's others up there too:

Convert to File type: uses photoshop to convert files files selected in Bridge to jpg, tiff, psd, png, eps, pict, and pdf

Create PDF - creates PDF's in AI and ID using presets from the point app from Bridge.

Rotate Images - applies the rotation flags in bridge to the image

Set Color Mode - sets color mode of images selected in bridge.

and more.

Bob
Adobe Workflow Scripting
Translate
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 Expert ,
Jun 29, 2005 Jun 29, 2005
Found an easy way round my grandchildren issue - just run a find at the root folder level. Bridge is now working its way through finding 10000 records.

I don't have the Suite. In fact, that's a bit of a raw nerve as I feel Adobe assume rather too readily that Photoshop users will need any of the other CS products. The integration I am looking for is with databases and catalogues, not Adobe's other graphics programs, so I want proper VB support. I don't like JavaScript much either, mainly because its editing environment is improved but still inadequate (for what we pay for Photoshop, it should have a scripting environment comparable to MS Office's VBE). /rant

Maybe I'll try writing that menu script myself!

John
Translate
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 02, 2005 Sep 02, 2005
LATEST
is there a way to test the "script manager" functionality if I only have Photoshop/Bridge and not whole Suite?
Translate
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