The Automatic Publisher

Today's Best Tech Deals

Picked by Macworld's Editors

Top Deals On Great Products

Picked by Techconnect's Editors

See the sidebars
"From Page to Web"
"Folder Actions"
· Apple's AppleScript
· Apple's Script Editor
· QuarkXPress 4.04 or later, or 3.X
· Adobe Photoshop 5
· Main Event PhotoScripter
· File-transfer utility

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.

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 programming–but 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:

tell application "Finder"
  open window of startup disk
  set position of window ¬
of startup disk to {30, 50}
end tell

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 activate 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 tell operators with an end tell 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 " Script Photoshop "). Even by scripting just these programs, you will enhance your productivity significantly.

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.

The QuarkXPress 4 BookReal World Photoshop 5

May 1999 page: 105

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.

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 tiresome–so 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 hot folders automatically run their scripts when you drop one or more files into them.

Note that while the scripts shown here will work "off the shelf," they won't work in all circumstances. You can download the full versions of the scripts, which are more robust and less likely to break, from here. You can modify the scripts to fit your needs or study them to learn basic concepts about creating your own. Don't forget some other important sources of information in your quest to learn more about AppleScript: Apple's AppleScript Page ( ), the AppleScript Sourcebook ( ), Everything CD for Mac Scripting ( ), and Scripting on the Web ( ).

1 Script QuarkXPress

Script QuarkXPress

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

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://" ¬
& "myfolder/myfile.html" ¬
Flags 1
end tell

This would open the proper HTML file in Explorer so you could make sure your ad looked correct on the final page.

Automate the Transfer
1 2 Page 1
Page 1 of 2
Shop Tech Products at Amazon