Running a Script in Photoshop CS2 from Bridge

Upload Adobe Bridge Scripts, Download Adobe Bridge Scripts, Support for Individual Adobe Bridge Scripts

Moderators: Tom, Kukurykus

Andrew

Running a Script in Photoshop CS2 from Bridge

Post by Andrew »

This is an example script that will create two new menu items in Bridge - one under a new heading 'Scripts' and another as a context menu when you right-click an image in the content pane. Clicking these will run the target script in Photoshop CS2.

You can paste the code and save into the StartupScripts folder, or do the same with the zip file.

Code: Select all#target bridge
if ( BridgeTalk.appName == "bridge" )  { // only load into bridge

   if (MenuElement.find ('scripts') == null) var ah_scriptsMenu = new MenuElement( "menu", "Scripts", "after Help", "scripts");
   var ah_runScriptImRn = new MenuElement( "command", "AH Image Rename", "at the beginning of scripts");
   var ah_runScriptImRnContext = new MenuElement("command","AH Image Rename","at the beginning of Thumbnail");
   
   ah_runScriptImRn.onSelect = function () {eval(ah_getTScriptString().replace(/ahxxxxxx/,'ah-rename.js'));}
   ah_runScriptImRnContext.onSelect = function () {eval(ah_getTScriptString().replace(/ahxxxxxx/,'ah-rename.js'));}
   function ah_getTScriptString() {
      return "function ah_GetScript2 (  )  {\
         var scp = 'ah_remoteScript2 = ' + ah_remoteScript2;\
         scp += 'ah_remoteScript2();';\
         return scp;\
      }\
      function ah_remoteScript2 ( ) {\
         var f = new File ('/c/Program Files/Adobe/Adobe Photoshop CS2/Presets/Scripts/ahxxxxxx');\
         if (f.open('r')) var sStr = f.read();\
         else throw('failed to open script'+f.fsName);\
         eval(sStr);\
      }\
      function ah_RunScript2  ( ) {\
         var bt = new BridgeTalk ();\
         var theScript = ah_GetScript2();\
         bt.target = 'photoshop';\
         bt.body = theScript;\
         bt.send();\
         BridgeTalk.bringToFront ('photoshop');\
      }\
      ah_RunScript2  ();"
   }   
}

A large part of the script consists of the function ah_getTScriptString() which simply returns a string which does the work of subsequently running the target script after the target script name has ben specified. It is not pretty but it works and it prevents function name collisions I was getting when I did not do it that way (given I am using multiple variations of this for different script targets).

Andrew