Legal
The views expressed in this blog are my own and do not necessarily reflect the views of Adobe Systems Incorporated.
Search
May
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Archives
May 09, 2006
Installing and using the ScriptingListener plug-in
Not all operations are scriptable using Photoshop's built-in methods. There are a couple of ways to get around this. One is calling a Photoshop Action from your script:
// Which Action(s) to run
doAction("My Great Action","Default Actions");
If you plan to share scripts with other users, this method requires that other users install the script and any Actions the script calls in order to run the desired operations.
The second is using the ScriptingListener plug-in to capture Javascript created by Photoshop to build Actions and incorporate this code directly into your script.
![]()
Installing the ScriptingListener plug-in:
Quit Photoshop
Locate the ScriptingListener plug-in inside Photoshop's application folder:
- Adobe Photoshop CS2>Scripting Guide>Utilities>ScriptingListener
Drag the ScriptingListener plug-in into the folder 'Automate' in Photoshop's Plug-Ins folder:
- Adobe Photoshop CS2>Plug-Ins>Adobe Photoshop Only>Automate
Launch Photoshop
Using the ScriptingListener plug-in:
As you work in Photoshop, the ScriptingListener plug-in records Javascript for any operation which is Actionable to a log file named ScriptingListenerJS.log, which by default is saved to the desktop on Macintosh, or to the root of your C:\ drive on Windows.

To determine if an operation is Actionable, double-click the ScriptingListenerJS.log file to launch the Console application. Keep the Console window view of the ScriptingListenerJS.log visible as you are working. You will see the log update if the operation you just performed is Actionable. Painting, for example, is not an Actionable operation. You can click 'Clear'' at any point to clear the entries in the log.

As you will notice, the Javascript which is recorded by the ScriptingListener plug-in isn't always easily read or clearly labeled.
For Example, here is some ScriptingListener Javascript for generating a guide:
// =======================================================
var id8 = charIDToTypeID( "Mk " );
var desc4 = new ActionDescriptor();
var id9 = charIDToTypeID( "Nw " );
var desc5 = new ActionDescriptor();
var id10 = charIDToTypeID( "Pstn" );
var id11 = charIDToTypeID( "#Rlt" );
desc5.putUnitDouble( id10, id11, 72.000000 );
var id12 = charIDToTypeID( "Ornt" );
var id13 = charIDToTypeID( "Ornt" );
var id14 = charIDToTypeID( "Vrtc" );
desc5.putEnumerated( id12, id13, id14 );
var id15 = charIDToTypeID( "Gd " );
desc4.putObject( id9, id15, desc5 );
executeAction( id8, desc4, DialogModes.NO );
Try to get in the habit of recording one step at a time and commenting each operation so you know what it does. I generally record the operation a few times with different settings so I can see where the settings change in the code. In this case, I've determined that 72.000000 refers to the pixel position of the guide, and that "Vrtc" is used for vertical guides and "Hrzn" is used for horizontal guides.
Here is the code with some comments:
// Create Vertical Guide
/*This javacript creates a vertical guide 72 pixels in from the left edge.*/
var id8 = charIDToTypeID( "Mk " );
var desc4 = new ActionDescriptor();
var id9 = charIDToTypeID( "Nw " );
var desc5 = new ActionDescriptor();
var id10 = charIDToTypeID( "Pstn" );
var id11 = charIDToTypeID( "#Rlt" );
desc5.putUnitDouble( id10, id11, 72.000000 );
var id12 = charIDToTypeID( "Ornt" );
var id13 = charIDToTypeID( "Ornt" );
var id14 = charIDToTypeID( "Vrtc" );
desc5.putEnumerated( id12, id13, id14 );
var id15 = charIDToTypeID( "Gd " );
desc4.putObject( id9, id15, desc5 );
executeAction( id8, desc4, DialogModes.NO );
You can also turn the Javascript that the ScriptingListener plug-in generates into your own functions. You can even pass in your own variables. In this case, we pass in an integer for pixelOffSet and the string "Vrtc", "Hrzn" for orientation:
function makeGuide(pixelOffSet, orientation) {
var id8 = charIDToTypeID( "Mk " );
var desc4 = new ActionDescriptor();
var id9 = charIDToTypeID( "Nw " );
var desc5 = new ActionDescriptor();
var id10 = charIDToTypeID( "Pstn" );
var id11 = charIDToTypeID( "#Rlt" );
desc5.putUnitDouble( id10, id11, pixelOffSet ); // integer
var id12 = charIDToTypeID( "Ornt" );
var id13 = charIDToTypeID( "Ornt" );
var id14 = charIDToTypeID( orientation ); // "Vrtc", "Hrzn"
desc5.putEnumerated( id12, id13, id14 );
var id15 = charIDToTypeID( "Gd " );
desc4.putObject( id9, id15, desc5 );
executeAction( id8, desc4, DialogModes.NO );
}
Then you can simply call the function every time you want to use it:
makeGuide(100, "Hrzn");
Using an 'include' to reference an external script
Another neat trick is to move all of your own functions created using the ScriptingListener into an external .jsx file. Then you can use an 'include' to reference the .jsx file with all your functions, keeping the script your working on neat and tidy.
Save your functions in a file 'myFunctions_lib.jsx' in the Photoshop's 'Scripts' directory:
- Adobe Photoshop CS2>Presets>Scripts
Next create a new script. Use an 'Include' to reference 'myFunctions_lib.jsx' file:
// Includes an external .jsx file
// @include 'myFunctions_lib.jsx'
Note: the 'Include' code will execute even though it looks like a comment.
Call the function 'makeGuide' from the 'myFunctions_lib.jsx' file:
makeGuide(100, "Hrzn");
Save the file as 'my_script.jsx' in the Photoshop's 'Scripts' directory:
- Adobe Photoshop CS2>Presets>Scripts
Run the script called 'my_script.jsx'.
If you want to comment out an 'Include' you can comment it using /* */.
// Includes an external .jsx file
/*// @include 'myFunctions_lib.jsx'*/