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.
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.
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.