Accurate Image Manipulation for Desktop Publishing
Photoshop

Adobe Photoshop CS2 Scripting

At work I manage a group of 10 Photoshop workstations and keeping them decently in consistent settings with our workflow has been a major burden for many many years. Finally in the beginning of 2007 I decided to take a look on how Photoshop Scripting could help.

And it did. Now I distribute WorkSpaces (the different layouts of the Photoshop screen elements) automatically via a network disk so all users have their own WorkSpace on every workstation. Similarly, Action Sets are automatically kept up-to-date, I change/add something to some ActionSet on one machine and that ActionSet is automatically updated by all the other Photoshops by the StartApplication event Script. Images from our various imaging systems are automatically identified and then automatically brought to workingRGB at open (by the Open event script) . And much more.

I keep the Scripts and Action Sets (as well as most of the other control files of Photoshop, lose color swatches, shapes etc) on the network drive, this way they are automatically up to date for all workstations and backing-up is very simple and automatic. Only a very few control files need to be located in the default Photoshop locations, one of them are the WorkSpace definition files, those are automatically distributed via the network disk.

Practically I do not anymore create individual Actions at all, I use the Action Buttons only to launch scripts, using the ScriptRunner. Actions are so limited and the task of creating and editing them is huge, I can easily create 10 or more scripts in that time that creating one Action takes. And, did I mention already, there is so very little than can be done with Actions.

I have got plenty of help, information and code examples from the active members on PS-Scripts forum, without this resource and the helpful people there, (particularly Xbytor and Mike Hale, Andrew, Patrick) I would not be anywhere near of releasing any Scripts. I could say that what really is mine in the scripts that I provide here is only the idea.

Some general purpose and utility Scripts

The below Scripts are all developed on CS2 and tested on Win2000 and WinXP. Currently I do no maintain version numbering for the Scripts, this is because quite often I restructure some code (in the include file) and that results that each and every one of my Scripts are changed. Instead I try to maintain the uploaded/updated date.

Filter All Visible Layers (uploaded 13-August-2007)

Applies a selected Filter to all visible Layers (the Layer visiblity is controlled by the eye icon in the Layer palette).

The selected filter is first applied to the active Layer using the normal GUI dialog. Any layer can be active, the script makes the other layers invisible during the dialog is shown.

After that the same filtering is sequentally automatically applied to all visible layers.

Currently supported filters

Average Layers.jsx (uploaded 12-August-2007)

Averages all the Layers. The number of Layers must be a power of two (2, 4, 8, 16, 32, 64, 128, 256, etc ), otherwise the script issues an error dialog. All the Layers must have 'Normal' Layer-mode with 'Opacity' == 100%, these are NOT inspected by the script. Note that accurate Average result is possible only when the Document is in a linear RGB working-space such as the CIE 1931 D65 RGB working-space. Do not have the Histogram palette open while running this script, it will slow down the script considerably. An obvious use of averaging is noise reduction, there are other more intereting uses also.

Noise averaging example

Stack by Extension.jsx (uploaded 11-August-2007)

This script presents a file open dialog, select one type of files (by extension) and the script loads all the images with that extension from the target folder as layers to a single new document. This script utilize the Place command of Photoshop, it is very fast. Note that when layering large amount of data (e.g. 256 layers of 1MB images is rather large for the typical office computer) there will be a delay after the script has completed, during this delay time Photoshop is desperately trying to figure out what it was what actually just happened and does not respond to anything, the length of this delay is about half of the run time of the script. Just wait patiently, on my computer the script loads 256 layers of 1MB images in about 90 seconds and then after 45 second delay Photoshop is again responding. Do not have the Histogram palette open while running this script, it will slow down the script considerably.

Camera RAW to workingRGB.jsx (uploaded 1-July-2007)

This is meant to be used as an Event driven script. As an event driven script it converts camera raw images (that are opened e.g. from ACR) automatically to the to working RGB. Save it to any folder, then use the File/Scripts/ScripEventManager to define an Open Event that runs this script.

It recognizes the following raw image extensions: cr2,crw,nef,pef,raf,x3f,bay,orf,srf,mrw,dcr but it is easy to add extensions to the list, just open the script to a text editor, edit the row:
var rawExtension = "cr2,crw,nef,pef,raf,x3f,bay,orf,srf,mrw,dcr";

ScriptRunner.jsx (updated 09-June-2007)

ScriptRunner provides organized, quick and dynamic method for using Scripts. It is run from an Action Button. It provides a dialog with a list, in alphabetical order, of all those JSX scripts in the folder where the ScriptRunner.jsx resides. A click on an entry will run that script. So, two click access to a set of your scripts, very rapid in the use.

Any number of ScriptRunners can be used. Simply organize your Scripts into folders, add a copy of ScriptRunner.jsx to each folder and finally create an ActionButton for each ScriptRunner.

Each ScriptRunner remembers the location of the dialog, for ease of use move the dialog close to the Action Button that starts the particular ScriptRunner. It will then open at that location, from session to session.

ScriptRunner.jsx example. Any number of ScriptRunners can be very easily employed, just create the folders, organize your scripts into them, copy a ScriptRunner.jsx into each folder and finally create the ActionButton for each ScriptRunner.

Reorganization of the Scripts is easy, simply move the Scripts from folder to folder, ScriptRunner will automatically adapt to the current content of the folders. Renaming of the Scripts is similarly easy, just do it and ScriptRunner will immediately adapt to that. For Script developers this is particularly useful feature since new versions are immediately available for launching, just behind two mouse clicks.

Installation:

  1. Save the ScriptRunner.jsx to a folder that has JSX scripts.
  2. Create a new Action, e.g. ScriptRunner (naming is free) into any suitable Action Set.
  3. Record the File/Scripts/Browse... 'ScriptRunner.jsx' as the only Step to the above created Action.

ScriptRunner.jsx require no modification to the code but a one-time-only configuration is required to Windows JSX file association, else the launched scripts do not run but are just opened the ExtendedScript Toolkit. Simply follow the instructions below.

Notes:

The ScriptRunner.jsx script will not perform the desired action unless you edit the File associations of the *.JSX using the WindowsExplorer. Change the 'Open' method to point to Photoshop, by default it is pointing to the ExtendedScriptToolKit.

This change has two effects:

  1. a double-click on a *.jsx file will run that script by Photoshop, instead of just opening it to ESTK. Use the Edit option from the pop-up menu in WindowsExplorer to open the file in the ESTK
  2. ESTK can be open when Scripts launch Scripts, this just a benefit.

This change does not affect the way Scripts in behave in general.

To change the JSX File Association, do the following in the Windows Explorer:

  • From the Tools menu
  • Select Folder Options
  • Select File Types -tab
  • Scroll down to JSX
  • Click once to select that JSX entry row
  • Click the Advanced button
  • Click the 'Open' method from the list
  • Click Edit button
  • Click Browse button
  • Browse to the Photoshop.exe and click to select it.
  • Click Open button
  • Click OK button
  • Click OK button

ActionSetChanger.jsx (updated 01-July-2007)

The ActionSetChanger rapidly changes (switches) the ActionSet that is displayed (loaded) to the Actions Palette. With only two mouse clicks.

ActionSetChanger is opened from an Action Button, it shows a dialog containing the names of your selected Action Sets, click on an entry In the replace mode and that Actions Set will swiftly replace the one that is currently loaded in the Actions Palette (and does belong to your selected Action Sets). Additional Action Sets can be loaded In the Add Mode, to toggle between the modes simply click the Mode row in the list. The actionSets that are currently loaded are indicated by the intend.

The ActionSetChanger dialog will remember its location from session to session, so place it below the ActionSetChanger Button and it will be very rapid to use.

ScreenCapture of the ActionSetChanger dialog.

The ActionSetChanger makes it very easy to use organized Action Sets, very efficiently. With the additional benefit that the size of the Actions Palette can be kept decently small.

Easy to take into use

    1. Create a new folder, e.g. 'ActionSetChanger' (naming is free) to a suitable location, any location on your HDD will do.
    2. Save both the 'ActionSetChanger_loader.jsx' and 'ActionSetChanger.jsx' to the folder created in step 1).
    3. Copy or move those of your Action Sets that you want include to the operation of the ActionSetChanger to the folder created in step 1).
    4. Create a new Action Set 'ActionSetChanger' (naming is not free, this set is ignored by the ActionSetChanger.jsx. It cab be used for other ActionButtons that must not change, such as the ScriptRunner buttons).
    5. Create a new Action e.g. 'ActionSetChanger' (naming is free) to the above created Action Set.
    6. Record the File/Scripts/Browse... 'ActionSetChanger_loader.jsx' as the only Step to the above created Action. Click the <Cancel > entry when the dialog appears, else the main ActionSetChanger.jsx will be recorded also.
    7. Save the above created Action Set to the folder created in step 1).

Notes:

No modifications are required to either of the scripts.

Anytime you want to add or remove Action Sets from the operation of the ActionSetChanger simply copy or remove Action Sets from the ActionSetChanger folder.

The script is in two parts, a loader and the actual script. The loader is needed because Photoshop does not allow full access to the Actions palette for such a script that was started from an action button.

AutoToggle.jsx (updated 09-June-2007)

The purpose of the AutoToggle is to help in making comparison. It toggles either:

  1. the visibility of the Active Layer, -OR-
  2. between two History States.

In case the History State was the last History State (in the History palette) at the time the script was started, then toggles the Active Layer On/Off.

In case the History State was NOT the last History State at the time the script was started (the user had stepped backwards in the History palette), then toggles between that current History State and the last History State.

When the Stop button (or the 'Esc' keyboard key) is pressed:

  • if it was toggling the Active Layer then the original Active Layer visibility is restored
  • if it was toggling the History State then the _last_ History State is restored.

The control dialog of AutoToggle. It remembers its location from session to session so drag it to a suitable place.

FullScreenToggle.jsx (updated 10-June-2007)

This script toggles the Screen Mode between FullScreen without Palettes and NormalScreen with Palettes, for all open images (each image windows has its own View Mode). Does FitOnScreen in both directions.

Installation:

  1. Save the FullScreenToggle.jsx to the \Adobe\Adobe Photoshop CS2\Presets\Scripts folder.
  2. Create a ShortCut key for FullScreenToggle.jsx (in Edit/Keyboard Shortcuts...). Do not use Alt+ shortcuts (since Scripts do not run if Alt is pressed when they are started, instead the Script is just opened to the ExtendedScript Toolkit.
  3. Create a Workspace that shows no palettes and save it with the name: '_sansPalette' (in Window/Workspace/Save Workspace ...) and only tick the Palette locations option.
  4. In case you have not already done so, create a working Workspace that also only saves the Palette locations, (it is good practice to keep the Keyboard and Menu customization in a dedicated Workspace that only saves those options). If you working Workspace definition does contain either Menu or Keyboard customizations then Photoshop will nag about possible changes to them every time you change the Workspace and every time the FullScreenToggle.jsx is run.

Notes:

  • The FullScreenToggle.jsx will automatically create/use/delete the WorkSpace '_FullScreenToggle'.
  • No modifications are required to this script.

myActions.jsx (uploaded 20-May-2007)

myActions rotates a predefined group of your selected Action Sets in the Action Palette. It is easily operated from an Action button. A dialog-less version of the ActionSetChanger. myActions is especially convenient when there is only two or three Action Sets in use. You define the Action Sets that you want to include to the rotation by editing a list in the 'myActions_main.jsx' script.

When the myAction Action Button is pressed the script looks if an Action Set from the list is currently shown in the Action palette, if such a Set is found it will be replaced (in the Actions palette) by the next entry from the list.

Does not alter the Action Set files (*.atn) on the disk in any way, only affects to what is shown in the Actions Palette.

The script is in two parts, a loader and the main routine. The loader is needed because Photoshop does not allow full access to the Actions palette for such a script that was started from an action button.

It is easy to take into use:

  1. Extract the two scripts to any folder (they both just need to be in the same folder).
  2. FIRST modify the two variables: actionsFolder' and actionSets' in the 'myActions_main.jsx' script.
  3. Create a new Action Set with the name: 'myActions'.
  4. Create a new Action with the name 'myActions' to the above created Set.
  5. Record the File/Scripts/Browse... 'myActions.jsx' as the only Step to the above created Action.

Steps 3,4, and 5 result a new Action Set that has only one Action, the myActions Button. If you load this as the first action set, it will be located nicely at top left, and then press it, it loads the first Action Set that is defined in the list.

The above is one time only job, later you only need to change the content of the actionSets variable in case you want to change, add or remove Actions Sets from the rotation.

getKeyState for more enthusiastic script developers, (uploaded 2-July-2007)

The getKeyState.exe is a helper application for Photoshop JSX scripting, written with VisualBasic. It enables to detect the state of the Shift, Ctrl keyboard keys and the state of the Left, Middle and Right mouse button, and the x,y position of the mouse, from within a JSX script.

The getKeyState.bas is the VisualBasic source code, provided for security reasons, the EXE can be converted using any 32-bit version of VisualBasic.

When the getKeyState.exe is run, it determines the state the above mentioned modifier buttons and writes this data into a keystate-id.ini to the directory where the getKeyState.exe was ran. The "id" in the ini file name is the computer-ID, necessary in multi-computer situations.

The getKeyState Readme.txt in the distribution package contains a sample JSX that demonstrates the usage of the getKeyState.exe.


Accurate Image Manipulation for Desktop Publishing

Copyright Timo Autiokari, 2007. Contact info