Creating, Editing, and Testing Scripts (The ExtendScript Toolkit)


When I first started writing scripts for Photoshop, I used a plain old text editor. It worked fine, but it was a somewhat laborious task to write the scripts and then switch over to Photoshop to test them. Plus, troubleshooting the scripts was a difficult process, as well. Then I discovered the ExtendScript Toolkit in Photoshop CS2. Thankfully, it's a script editor that was created specifically for editing scripts in Photoshop and it really helps speed things up.

Step One

First, you'll need to find the ExtendScript Toolkit. You may have even seen it before but not known it. On the Mac, go to Hard Drive:Applications:Utilities:Adobe Utilities:ExtendScript Toolkit. In Windows, you'll find it on your Start Menu, under All Programs>Adobe>ExtendScript Toolkit.

Step Two

Open the Toolkit editor. You'll see a window with Photoshop-like palettes on the left and a text editor on the right.

Turbo Boost

If you're running or testing a script in the ExtendScript Toolkit and nothing seems to be happening, try clicking the Stop button to forcefully stop the script.


Step Three

Choose File>New JavaScript. This will create a blank file with an area on the right ready for you to type.

You can write Photoshop scripts using JavaScript, VBScript(for Windows), or Applescript (for Mac OS). However, JavaScript is the only cross-platform scripting language, meaning it performs identically in both Windows and Mac OS. Keep this in mind, as you'll save yourself a lot of time by writing most of your scripts in JavaScript (as I have done throughout this tutorial), so everyone can use them.


Step Four

Type the text shown here into the text editor. This code creates a new dialog in Photoshop. I'd like to draw your attention to something, though. Look at Line 9. See how it contains the string dlg.txtName? This creates a text box in the new dialog for us to enter text. Behind the scenes, Photoshop is referring to this text box by its name, which is txtName. (Note: You can download this script at www.scottkelbybooks.com/speedclinic, in case you don't want to type in everything in Steps Four through Seven.)

Turbo Boost

You can save JavaScript files with a JS or JSX extension on the end of them. If you use the JSX extension, the files will automatically open in the ExtendScript Toolkit.


Step Five

Now you'll need to test the script, which luckily is very easy when you're using the ExtendScript Toolkit. First, select Adobe Photoshop CS2 from the first pop-up menu on the top left. Next, click the Run button. Photoshop CS2 will be launched, if it isn't already. Then the window will switch over to Photoshop and your script will run behind the scenes.

At this point, all we've done is create a dialog with a text box and a button. It should look like the dialog shown here.

Step Six

This dialog won't actually do anything yet, though. To make it actually do something, type in the code shown here between your original Line 1 and your original Line 3 (which becomes Line 20, as you can see here).

Turbo Boost

Check out the JavaScript Reference Guide in Adobe Photoshop CS2's Scripting Guide folder on your hard drive. It is the fastest way to get up to speed with scripting in Photoshop as well as the ExtendScript Toolkit.


Be on the lookout for errors, as they can really slow you up if you don't know what to look for. You'll know pretty quickly because your computer should beep at you and you'll see a red line at the place of the error. ExtendScript Toolkit will even tell you what the error is in the JavaScript Console at the top left.


Step Seven

Now the script is done. However, before you run it take a look at Line 16. Notice it refers to an action called Gallery Print. You can actually call actions from scripts to really enhance the power you have to automate things in Photoshop. In order to use this script, be sure to download the Gallery Print action (Speed Clinic.atn) from www.scottkelbybooks.com/speedclinic and load it into your Actions palette. If not, the script will not work. To load it into your Actions palette, first download the file into your Photoshop Actions folder, which is in Adobe Photoshop CS2's Presets folder. Then, from the Actions palette's flyout menu, choose Load Actions. In the resulting dialog, select Speed Clinic.atn and click Load. It should now appear at the bottom of your palette.

Turbo Boost

Before you run a script using the ExtendScript Toolkit, you can check your code by choosing Edit>Check Syntax or press Command-Shift-K (PC: F7).


Step Eight

After you're done testing the script, you can name it "SpeedClinic" and save it into Photoshop CS2's Scripts folder, which is in the Presets folder. Then restart Photoshop, and it'll show up in the Scripts menu.

©MATT KLOSKOWSKI

Step Nine

Open a photo in Photoshop. Choose File>Scripts>SpeedClinic and type in your name or a name for the photo in the text box. Press the Run button, and watch Photoshop work its magic by adding the text you entered and creating a gallery print from your photo. You'd never be able to use dynamic text in an action like this. An action would always add the same exact text. With a script, you can choose the text each time you run it.

Turbo Boost

When using the ExtendScript Toolkit, you can press Command-K (PC: Control-K) to get the Preferences dialog. Choose Font Options from the top pop-up menu to make the font size larger or smaller.




Photoshop CS2 Speed Clinic
The Photoshop CS2 Speed Clinic: Automating Photoshop to Get Twice the Work Done in Half the Time
ISBN: 0321441656
EAN: 2147483647
Year: 2006
Pages: 113

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net