You'll get your Mac news here from now on...

Help TMO Grow

Subscriber Login

Advertising Info


The Mac Observer Express Daily Newsletter


More Info

Site Navigation

Home
News
Tips
Columns & Editorials
Reviews
Reports
Archives
Search
Forums
Links
Mac Links
Software
Reports
Contact



by Stephen Swift


AppleScript In Mac OS X: A Brave New World
May 22nd, 2002

[Author's Note: This marks the 6th installment of AppleScript: The Macintosh Autopilot. If you find any of this tutorial not making sense, check out the some of the earlier installments.]

After an hour of Mac OS X, you decided that Mac OS 9 is as outdated as System 7. You're just about to snuggle in when you realize that something doesn't feel right. You're missing your AppleScripts, right? I know the feeling. Don't despair! Once inside Mac OS X, AppleScript is easy; however, the transition can be a little rocky. That's why I'm providing you with these instructions on updating your scripts for Mac OS X.

Upgrade! The most recent version of AppleScript for Mac OS X is 1.8.1. It offers the best compatibility for your scripts between the systems and most scripting versatility. My tips pertain to this version and may not work on other AppleScript versions.

COMPILE, COMPILE, COMPILE

Mac OS X should recognize your scripts. Most of them will need a recompile to verify that everything is hunky-dory in this new system. Luckily for you, Apple's AppleScript Swiss army knife, the Script Editor, hasn't changed aside from the new Aqua face lift.

Start Slow

Convert your small scripts (10 lines or less) first. If you try to convert huge scripts, you'll just run into error after error. What fun is that? Pay attention to what Mac OS X balks at. I recommend looking at scripts that deal mostly with 3rd party applications. Scripts that use Eudora's dictionary, for example, should have little problems. Scripts that interact with the Finder a great deal will need the most tweaking. After all, the Finder is the application that has changed the most from Classic to Mac OS X. Read the section on compatibility to learn more on what you can do to smooth out this problem.

Pay attention to scripts that work with applications that do not run in the Mac OS X environment such as Photoshop. You have a few options here. If your script needs to access Photoshop repeatedly, I recommend to check the box in the Finder's Get Info window of the script to specify that it open in the classic environment. However, if you only need to use Photoshop for a little part in your script, AppleScript can access the Classic programs while running in the Mac OS X environment. Yes, that is cool.

Run A Script

I find the easiest way to run my scripts in Mac OS X is through the Script Menu. If you save your scripts as applications, they should be saved in a universal-format that will run in Classic (under Mac OS X), OS 9, or OS X. However, you could still use commands that would trip up one of the operating systems. Make sure the commands you use are compatible and the syntax works with each system. Again, I'll get to that soon.

What about scheduling scripts? Well, I haven't heard from iDo yet, but there is a program called Script Timer that will run scripts at any time you want. It runs both in Mac OS X and 9. For more information on all its cool features check out their Web site.

Compatibility

I find the number one problem to be trying to make a script that will work in Mac OS 9 and X perfectly. As Mac OS X and AppleScript develops, this becomes easier. You must test your script on both systems. Sometimes, you may have to end up creating two different versions of the same script.

The Obvious Pit-Falls:

  1. Mac OS X does not yet have pop-up folders or folder actions.
  2. There is no button view, but now there are columns.
  3. Mac OS 9 has no dock or UNIX kernel.
  4. Any other major change that people praise or gripe about. :-)

I can't list every syntax change partly because I haven't encountered all of the changes yet. Here's what you can do:

  1. Download the Essential Sub-routines help file for Mac OS 9 and Mac OS X. These are great tools for the "I can't remember how to..." questions. Compare how each system expects the commands to be given to it. They cover much of the basic syntax.
  2. Look at AppleScript examples from Apple. They have iPhoto, QuickTime, Sherlock, TexEdit, and iTunes examples. Also look at their toolbar scripts to get a feel for how the Finder handles folders and windows. All these are great reference material. When your script is giving you errors, check Apple's examples to see how they wrote their code.
  3. Search Apple's built in help for explanations on how to use AppleScripts in Mac OS 9 and X.

Scripting Additions

Here's a can of worms if I ever encountered one! You need to check each script to see if it uses any Scripting Additions. The Standard Additions and ones from Apple should be fine. You'll run into problems if your script uses third party additions.

If you want to use scripting additions found in the Classic environment, your best solution is to stay in the Classic environment. Save your script as an application and make sure to check the "open in Classic" option in the Finder's Get Info window. If you need to access classic scripting additions and send commands to Mac OS X, then I will direct you to an in depth analysis of your situation.

Check the Scripting Additions Web site regularly to see what additions have been ported over to the Mac OS. They can be installed in many places such as the Scripting Additions folder or in a specific user's Scripting Additions folder. Most Mac OS X scripting additions should come with documentation that explains how to use them in much more detail. Not many additions have been ported over, making it somewhat difficult for the advanced scripter to switch over to Mac OS X. Hopefully, we'll see more additions soon!

NEXT TIME

Oh boy! I didn't get to cover a lot of really neat and new Mac OS X specific AppleScript goodies; it's important that everyone has made a smooth transition from Mac OS 9 first. To those of you who didn't need to do a lot converting for your old scripts, familiarize yourself with the new system. Look at the examples and try to create your own scripts. Look forward to building Mac OS X scripts from scratch, taking advantage of new commands! Also, I'll take you on a tour of the AppleScript Studio and show you what you need to know to create really beautiful scripts. There will still be a lot of relevant information for those of you working in Mac OS 9; however, you should seriously think about upgrading if only to fiddle with the new system. It is really amazing. If anyone gets stuck, please send an e-mail to Stephen@macobserver.com and I'll help you out!

AppleScript on Mac OS X is a learning experience for everyone. There will be new features and problems. I hope everyone is as excited as I am as we bravely explore this new world.


Comments or Questions? Is this column going to slow or fast for you? Do you want to script something, but don't know how? Do you need something explained or have a question about a script?  My E-mail address, stephen@macobserver.com, is open 24 hours a day, 7 days a week.


Most Recent AppleScript Columns

Break Your Script Into Pieces with Subroutines
June 26th

Repeat Yourself With AppleScript
June 12th

AppleScript Lists
June 5th

AppleScript Archives

Back to The Mac Observer For More Mac News!



Today's Mac Headlines

[Podcast]Podcast - Apple Weekly Report #135: Apple Lawsuits, Banned iPhone Ad, Green MacBook Ad

We also offer Today's News On One Page!

Yesterday's News

 

[Podcast]Podcast - Mac Geek Gab #178: Batch Permission Changes, Encrypting Follow-up, Re-Enabling AirPort, and GigE speeds

We also offer Yesterday's News On One Page!

Mac Products Guide
New Arrivals
New and updated products added to the Guide.

Hot Deals
Great prices on hot selling Mac products from your favorite Macintosh resellers.

Special Offers
Promotions and offers direct from Macintosh developers and magazines.

Software
Browse the software section for over 17,000 Macintosh applications and software titles.

Hardware
Over 4,000 peripherals and accessories such as cameras, printers, scanners, keyboards, mice and more.

© All information presented on this site is copyrighted by The Mac Observer except where otherwise noted. No portion of this site may be copied without express written consent. Other sites are invited to link to any aspect of this site provided that all content is presented in its original form and is not placed within another .