UNDERSTANDING PHOTOSHOP SCRIPTING


Scripting and actions both help you automate tasks in the Adobe Creative Suite. Scripts are actual programs you write (or record) to perform tasks. Photoshop, Illustrator, and InDesign can use OLE-compatible scripting languages (such as Visual Basic) on Windows computers, AppleScript on Macintosh computers, and the less-powerful JavaScript on both. Scripts not only can perform tasks within a program, they can call or invoke other programs (accessing the second program and its features) and even work with hardware and the operating system.

Actions, in contrast to scripts, are a series of recorded steps within the program. They cannot talk to other programs. Logic can be built into actions using Conditional Mode Change. Conditional Mode Change is a Photoshop automation function that applies rules to change the image color mode based on certain conditions. For example, part of an action may require the image to be in CMYK mode and another part of an action may require RGB mode. Here, Conditional Mode Change is helpful. Refer to the Adobe Help Center for information on Condition Mode Change.

Scripting and the Adobe Creative Suite

Think of scripting as that studio assistant you can't afford to hirethe one who does all the little tasks, freeing you to be creative and dynamic. No, scripting won't make coffee (yet), but it will handle many of the small-but-important tasks that seem to eat up the workday.

Scripting can also be used for those jobs not within the scope of actions. Have you ever wanted to add the name of a file in, say, the lower-left corner of the image, along with your copyright information? And you wanted to do this to an entire folder of imageswithout losing a night's sleep? What if the images are not the same size or orientation? An action in Photoshop or Illustrator isn't capable of determining whether an image is portrait or landscape oriented. Scripts, on the other hand, can be written to handle such jobs. A script can get information, evaluate that information and perform calculations, and make decisions based on the information. Actions, on the other hand, are "dumb"they can perform only the same steps and settings with which they were recorded.

Each of the scriptable members of the Adobe Creative Suite can be controlled with JavaScript, Visual Basic (Windows), or AppleScript (Mac). Again, the purpose of this chapter is not to teach programming or scripting languages. Instead, this chapter introduces you to the possibilities and then provides you with resources that enable you to capitalize on those opportunities to improve efficiency and free more time for creativity.

Virtually every aspect of Photoshop, Illustrator, and InDesign can be controlled through scripting. Visual Basic and AppleScript can call programs outside of the program within which you're running the script. Running a script in Photoshop could, for example, open Illustrator, find a specific piece of artwork, copy it, switch back to Photoshop, paste the artwork, save the file in a format appropriate for print, open InDesign, add the Photoshop file to a document, save the document, and print the proof. In a nutshell, if you can do it using the keyboard and mouse, it can probably be recorded in Visual Basic or AppleScript. And don't overlook the fact that a script can play an action within Photoshop or Illustrator.

Remember one key difference between using JavaScript and Visual Basic or AppleScript: JavaScript cannot call or invoke another programit runs only within the host program.


Understanding JavaScript, AppleScript, and Visual Basic: Which One?

JavaScript is cross-platformmeaning the same script performs identically on both Windows and Macintosh versions of your programs. However, a JavaScript must be run from within the program and cannot call another program. AppleScript and Visual Basic are more powerful, can be run from outside a specific program, and can run multiple programs. However, they are both platform specifican AppleScript cannot be used in Windows, and Visual Basic cannot run on a Macintosh.

Inside Photoshop CS2's Scripting Guide folder, you find the ScriptListener plug-in. When installed, ScriptListener records most of what you do in Photoshop as JavaScript code in a file at the root level of your hard drive. For Windows, it also creates VBScript code in a separate file. (AppleScripts call the JavaScript.) Install ScriptListener in Photoshop's Plug-Ins folder only when you actually use it to create scripts. Photoshop might run more slowly with the plug-in installed, and it generates a file on your hard drive that is otherwise not required.


Keep in mind that both AppleScripts and Visual Basic scripts can execute a JavaScript, but JavaScripts can't call the others.

Scripting Resources Supplied with the Adobe Creative Suite

Each of the scriptable members of the Adobe Creative Suite (Photoshop, Illustrator, and InDesign) has some scripts included with the program, as well as additional resources and information either on CD or available through www.adobe.com.

Photoshop CS2 Scripts

Under the File, Scripts menu, you find a few JavaScripts that can be very handy: Export Layers to Files, Layer Comps to Files, Layer Comps to PDF, and Layer Comps to WPG. New in Photoshop CS2 is the excellent Image Processor and the Script Events Manager.

Inside the Photoshop folder on your hard drive, you find the Scripting Guide folder. In PDF format, you see reference guides for Photoshop scripting in general (91 pages), JavaScript (335 pages), AppleScript (251 pages), and Visual Basic (178 pages). That is definitely a lot of reading, and these guides and sample scripts are the very best resource for learning scripting in Photoshop. In addition, the folder contains additional prerecorded scripts (27 JavaScript, 18 AppleScript, and 19 Visual Basic). You can use these scripts, or open them for study.

Remember, too, that resources are available to you at www.adobe.com in the Expert Centers for each product. You also find assistance and information in the various scripting forums within the product forums of www.adobe.com.

Loading a Sample JavaScript

The sample scripts mentioned earlier can be added to Photoshop as long as you know where to put them. You can load a script for use one time, or copy them to the Scripts directory to put them under the Scripts menu the next time you launch Photoshop. Choose File, Scripts, Browse. From here you can browse to the Sample Scripts folder in the Scripting Guide folder. Select the ExecuteMoltenLead.jsx script and click Load. A new layer of molten lead is created by the script. If you don't have a document open, the script creates a new document for you and emblazons it with lead. You can put any of these sample scripts permanently under the Script menu. Copy the JSX files to your Presets, Scripts folder in the Photoshop CS2 folder. Close and relaunch Photoshop, and look under the File, Scripts menu for your sample scripts to appear in the list. For more scripts go to http://share.studio.adobe.com.

Learning More About Scripting…

Here are some online resources you can use to learn more about scripting:

  • www.javascript.com

  • www.javascriptcity.com

  • http://javascript.internet.com/tutorials/

  • http://www.apple.com/macosx/features/applescript/

  • www.applescriptsourcebook.com

  • www.macscripting.com

  • www.scriptweb.com

  • http://msdn.microsoft.com/vbasic/

  • www.developer.com/net/vb/

The Internet is just one source of information on scripting. Especially if you're new to high-level automation, check out these additional resources:

  • Special Edition Using JavaScript by Paul McFedries (Que Publishing)

  • JavaScript Goodies by Joe Burns and Andree Growney (Que Publishing)

  • Sams Teach Yourself JavaScript in 24 Hours by Michael Moncur (Sams Publishing)

  • Sams Teach Yourself JavaScript in 21 Days by Jonathan Watt, Andrew Watt, and Jinjer Simon (Sams Publishing)

  • Visual Basic .NET Primer Plus by Jack Purdum (Sams Publishing)




Special Edition Using Adobe Creative Suite 2
Special Edition Using Adobe Creative Suite 2
ISBN: 0789733676
EAN: 2147483647
Year: 2005
Pages: 426
Authors: Michael Smick

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