Earthbound Light - Nature Photography from the Pacific Northwest and beyond by Bob Johnson
Home
About
Portfolio
Online Ordering
Contact
Comments
Recent Updates
Support

Photo Tip of the Week
CurrentArchivesSubscribeSearch

Scripting with the Photoshop ScriptListener Plug-in

At some point while learning the art of scripting in Photoshop you are bound to run up against something that seems to have no way to be done based on Adobe's documentation. Even at hundreds of pages, there are things you can do in Photoshop that don't seem doable in script if you limit yourself to what Adobe tells everyone about. Thankfully, there's the ScriptListener.

The ScriptListener is a Photoshop plug-in. Once installed, it will observe everything you do in Photoshop and log it to two files in the form of script code. One file will contain everything you do written as JavaScript, and the other will contain the exact same thing but written as VBScript. Mac OS users should be advised that ScriptListener does not provide support for AppleScript output. Be forewarned that this is not something you will want to leave installed all the time since the generated files can grow large quite rapidly. Having it installed will also slow Photoshop down modestly, although most users won't really notice the difference. I assure you though, you will notice the huge and ever growing files that ScriptListener creates.

To install the ScriptListener plug-in, simply copy the file "ScriptListener.8li" from "C:\Program Files (x86)\Adobe\Adobe Photoshop CS4\Scripting\Utilities" your regular plug-in folder "C:\Program Files (x86)\Adobe\Adobe Photoshop CS4\Plug-ins." These paths are for standard 32-bit installations on Windows but the 64-bit Windows and Mac OS paths are similar. Everything lives underneath your Photoshop installation folder either as "Scripting\Utilities" or "Plug-ins" so you should hopefully be able to find both folders on your computer without too much difficulty. As with any new plug-in, you will need to restart Photoshop for it to see the ScriptListener plug-in and start logging things. Once Photoshop is running again and you do something, you should see the files ScriptingListenerJS.log and ScriptingListenerVB.log show up on your Desktop. Note that for some inexplicable reason the output log files are "Scripting Listener" while the name of the plug-in that creates them is "Script Listener." Lack of consistency notwithstanding, it's great that Adobe provides this capability as we shall see in a bit.

Uninstalling ScriptListener consists simply of deleting the "ScriptListener.8li" from your Plug-ins folder and restarting Photoshop again. When installing ScriptListener, make sure you copy "ScriptListener.8li" rather than move it so that when you uninstall you haven't deleted your only copy. If you do goof and lose the file completely you can always copy it back from your original Photoshop installation DVD.

The output of the ScriptListener is not a model of well written code. Being spit out by an automated process rather than a person, variables aren't names in any meaningful way. It also has a propensity for scripting things in ways that Adobe doesn't document in their voluminous scripting guide. This may seem to be a bad thing, but it does have the advantage of allowing it to script virtually anything, even when no documented way seems to exist to do so. Even many third party filters can be scripted to one degree or another this way. Pretty much anything that's part of Photoshop itself can be. As ugly as the generated code is though, it will execute just fine. Simply take the relevant snippet from the ScriptingListenerJS.log and paste it into your script, then tweak as necessary. Although ScriptListener code is filled with stuff Adobe doesn't tell the rest of us about, you should still be able to tailor its output to meet your needs. We looked a couple weeks back at how to rotate the active document by ninety degrees using JavaScript/ExtendScript. It took just a single line of code:

  activeDocument.rotateCanvas(90);

Now here's the equivalent as generated by the ScriptListener Plug-in:

  // =======================================================  
  var idRtte = charIDToTypeID( "Rtte" );
    var desc3 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
      var ref1 = new ActionReference();
      var idDcmn = charIDToTypeID( "Dcmn" );
      var idOrdn = charIDToTypeID( "Ordn" );
      var idFrst = charIDToTypeID( "Frst" );
      ref1.putEnumerated( idDcmn, idOrdn, idFrst );
    desc3.putReference( idnull, ref1 );
    var idAngl = charIDToTypeID( "Angl" );
    var idAng = charIDToTypeID( "#Ang" );
    desc3.putUnitDouble( idAngl, idAng, 90.000000 );
  executeAction( idRtte, desc3, DialogModes.NO );

The ninety degrees is definitely in there. And I guess we can assume that "Rtte" somehow means "rotate," but much of the rest is rather cryptic. Regardless, it does work. And if you plug in some other number in place of 90.000000 you can rotate by other angles.

If you can do something through the standard, documented Photoshop Object Model you will end up with much more readable and understandable code, but for when nothing else will do, the ScriptListener can be a lifesaver.


Date posted: June 20, 2010

 

Copyright © 2010 Bob Johnson, Earthbound Light - all rights reserved.
Permanent link for this article
 

Previous tip: Scripting with the ExtendScript Toolkit Return to archives menu Next tip: Preventing and Resolving Photoshop CS5 Installation Problems

Related articles:
Intro to Photoshop Scripting
Creating Your First Script in Photoshop
Scripting with the ExtendScript Toolkit
 

Tweet this page       Bookmark and Share       Subscribe on Facebook via NetworkedBlogs       Printer Friendly Version

Machine translation:   Español   |   Deutsch   |   Français   |   Italiano   |   Português


A new photo tip is posted each Sunday, so please check back regularly.


Support Earthbound Light by buying from B&H; Photo
  Buy a good book
Click here for book recommendations
Support Earthbound Light
  Or say thanks the easy way with PayPal if you prefer



Home  |  About  |  Portfolio  |  WebStore  |  PhotoTips  |  Contact  |  Comments  |  Updates  |  Support
Nature Photography from the Pacific Northwest and beyond by Bob Johnson


View Cart  |  Store Policies  |  Terms of Use  |  Your Privacy