See the sidebars
“From Page to Web”
The Mac is better suited than ever to automating your work, although that wasn’t always the case. Ten years ago, if you needed to automate your computer, it was better to get a PC. The Macintosh operating system just wasn’t set up for batch processing and scripted automation. But the tides have changedthe Macintosh now ships with the superior automation system.
WHAT YOU NEED
Apple’s Script Editor
QuarkXPress 4.04 or later, or 3.X
Adobe Photoshop 5
Main Event PhotoScripter
The key to automating your Mac is AppleScript, which is built into the operating system. AppleScript 1.3 (the version that comes with System 8.5) is finally PowerPC native, which means it’s several times faster than it was in older systems. Even better, you can now attach scripts to folders so that when you interact with a folder (for instance, add a file or move the folder’s window), the script runs automatically.
With these attached scripts, called folder actions, you can trigger a whole sequence of steps simply by dragging a file into a specific folder or by opening a folder. You could, for instance, trigger a script that has your Mac save a piece of artwork as an EPS file in QuarkXPress, rasterize it in Adobe Photoshop, and then place it on your Web server.
In fact, that’s exactly what the scripts in this article do (see “From Page to Web”). You can use them, with minor modifications, to automate your publishing process.
Have No Fear
Before I dive into the heavy-duty process of scripting QuarkXPress, Photoshop, and a file-transfer utility, let me first show you how simple AppleScript can be. Telling your computer what to do is technically computer programmingbut before you panic, remember that AppleScript is different from any other kind of programming. First of all, you don’t need any special software to write these kinds of programs. Second, the AppleScript language looks like everyday English.
Keeping the panic under control is important, because AppleScript is an incredibly powerful language that can speed up your work and make your life exponentially better. If you’ve never programmed before, here’s your chance to find out how much fun it is to write something in text and have your computer follow your orders. Try this:
1. Fire up the Script Editor application (you’ll find it in the Apple Extras folder on your hard drive unless you’ve moved or deleted the application). Several commercial applications on the market let you script easier and faster than Script Editor, but this one is free.
2. Type this script:
3. Finally, click on the Run button in Script Editor to see the script in action.
This script is not only a simple introduction to AppleScript, but also demonstrates a few of the syntax rules to follow when writing your own scripts. First, you must direct your commands to a particular application or object. This script directs commands at the Finder itself. The word
tells the Finder to become the active, frontmost application. The
character (option-L) means that the command continues on the next line. To specify a position for an object on screen, set the coordinates inside braces. In my example, the script sets the hard drive’s window at 30 pixels in and 50 pixels down. Finally, you must match all
operators with an
command (it’s like saying “at ease” to the application).
The more complex the task, the more complex the script. But you can do powerful operations even with simple scripts.
Being able to script the Finder is pretty cool. Being able to script the Finder in conjunction with other programs is awesome. For instance, AppleScript can take a FileMaker Pro database full of information and build a fully formatted catalog or directory in under a minute (this is how some newspapers create their daily television guides and weather information). Similarly, AppleScript can process a folder full of XPress documents, converting all the fake fractions into true ones. AppleScript can even parse your e-mail (in Eudora Pro or Claris Emailer) and take action based on what it finds.
While you can’t automate all applications with AppleScript, you can script many key players, such as QuarkXPress. Photoshop is also scriptable, but in a limited way (see ”
“). Even by scripting just these programs, you will enhance your productivity significantly.
What about Macros?
The most important difference between scripting and macros is that scripting lets you query the program you’re automating. For instance, a script could ask QuarkXPress what the name of the current document is and then type that name into a text box on every page of your document. While macros can be useful, there’s no way they can perform a task like this. Go with AppleScript when you need efficiency and power.
DAVID BLATNER is the author of
The QuarkXPress 4 Book
(Peachpit Press, 1998) and a coauthor of
Real World Photoshop 5
(Peachpit Press, 1999).
The ability to attach AppleScripts to folders (new in System 8.5) is extraordinary. You can start a script action in any of five ways: open or close a folder, move a folder’s open window, and add items to or remove them from a folder.
Unfortunately, the procedure for attaching a script to a folder is a little obscure. You must first write an AppleScript in a program such as Script Editor. Then, add one or more of the special new on scripting commands (see the sample scripts here for examples).
You can get more information about how to write scripts for folder actions by selecting AppleScript Help from the Help menu in Script Editor.
From Page to Web
Even better than automating a single mundane task is automating an entire workflow. The scripts here show how you can automate the process of converting a QuarkXPress document into a Web-ready file, using AppleScript, QuarkXPress, Photoshop, Dartmouth College’s Fetch, and Internet Explorer. The specific process I’m illustrating is updating a Web page with an ad created in QuarkXPress.
It’s easy to get an ad in XPress onto the Web even without AppleScript: just save the ad as an EPS file, rasterize it (turn it into a bitmap) in Photoshop, save it to disk as a GIF or JPEG, and put it on your Web server. But if you had to change the ad everyday, this process would soon get tiresomeso why not automate the workflow?
I built this workflow with three scripts, each attached to a folder using System 8.5’s new Folder &365;ctions feature (see “Folder Actions”). These
automatically run their scripts when you drop one or more files into them.
QuarkXPress is ideal for making simple ads because it has great typographic features and lets you repurpose content that you’ve already used in print materials. XPress is also one of the most scriptable and scripted applications on the Mac. Here I’ve built an ad in a document that is the same size as the ad itself so that I won’t need to worry about cropping it later. After building the ad, the first step is to export it as an EPS file from QuarkXPress. Here, the script reads item 1 of added_items in case someone drags more than one file into the folder. If the file is an XPress document, the script exports the first page as an EPS file and then closes the document.
If you want to script XPress 4, make sure you’re using version 4.04 or later (earlier versions were too buggy to bother with). Also note that many scripts that worked with QuarkXPress 3.X require modifications to work with XPress 4, because of the way the newer version handles boxes (especially Bézier boxes).
2 Script Photoshop
People who script have clamored for Adobe to make Photoshop AppleScriptable for years. Unfortunately, the cries have fallen on deaf ears, and Photoshop lets you use scripting only to open files (using the open command) and run premade Photoshop Actions (using the do script command). Photoshop also lets you batch-process a folder of images using one or more Actions, but only from within the program, not via scripting. While you can do a lot within these constraints, they leave much to be desired. Fortunately, Main Event (
) has released PhotoScripter, a plug-in that adds scripting functionality to Photoshop 5.
Photoshop’s Actions are easy to create, but PhotoScripter beats them out in several ways. For instance, the second step in my workflow (converting the EPS file to a JPEG) would be impossible to do as an Action.
When attached to a folder, this AppleScript uses the EPS Generic filter to open in Photoshop any EPS files that appear in the folder. You can control all the important properties of the Open As Generic EPS dialog box here: color space, antialiasing, and size.
3 Automate the Transfer
The final step in this automated workflow is to get the new JPEG image onto my Web server. Fortunately, you can script both Fetch and Stairways Software’s Anarchie Pro (these file-transfer utilities are shareware, available at online sites, including
). In my sample script, I use Fetch. This script, also set up as a Folder action, launches as soon as the JPEG file drops into its folder, immediately uploading it to the proper folder on the Web site. (You should replace this Web site with your own, of course.)
The script doesn’t have to end here. For example, you could add another line at the end of the script that reads:
tell application “Internet Explorer 4.01”
openURL “http://http://www.macworld.com/” ¬
& “myfolder/myfile.html” ¬
This would open the proper HTML file in Explorer so you could make sure your ad looked correct on the final page.
Note: When you purchase something after clicking links in our articles, we may earn a small commission. Read ouraffiliate link policyfor more details.