My past, present and future scripting

Hello,
As of early March 2004, I was working in OS9.2.2 on a G4 cube where I was able to use a combination of Applescript (some scripting additions), OneClick and OSA Menu to ease the somewhat tedious task of doing production graphics (1000s) year in year out at an educational institute where I work. The above tools were complementary; what was lacking in scripting the user interface in Applescript was easily filled by OneClick and both scripting environments interacted with each other quite well. When I first looked at Applescript some years back, it seemed quite a bear when trying to get any results from it. I just didn’t really understand what it could do for me. A few years later, I discovered OneClick and found that it converted your various actions into single line scripts; but it could go way beyond just recording actions. One could go in and edit these script lines, create conditional statements, batch process files, handle values from Applescript variables and vice versa, etc. Building app-specific palettes was, for what I was doing, superior to key shortcuts. Previous to Oneclick, I used Quickeys for awhile but I found it didn’t have the depth or flexibility I was looking for. I found that the programs that I used daily–Canvas 8 and Filemaker Pro 5.5–had great Applescript support along with their own respective scripting environments and ‘talked’ to each other well. In my day to day operation then, there was almost nothing that I couldn’t automate or shortcut.

Near end of March, I took the leap and went to a G5 with OS 10.3. Because of this, I’ve had to start rebuilding most of my automation Applescripts (only 1 works so far). None of the other Oneclick scripts worked. Westcode software (http://www.westcodesoft.com/) informed me that, because of the difference between OS9 and OSX, it would be impossible to port Oneclick to OSX. So, what are the options? I’ve been trying to make due with Apple’s new GUI scripting environment using Prefab’s UI Browser (http://www.prefab.com/). It’s been a rather slow process as I’m finding that certain things are not as scriptable or as easy to script as I thought. I looked at Quickeys again briefly and chose to start working with iKey (http://www.scriptsoftware.com/ikey/) to fill in some of the user interface gaps. I hear that version 2.0 for iKey will be out soon. So far, I’m still not automated to the degree that I was in OS9.

My ideal script environment: Being able to perform all kinds of user actions, etc. while Applescript is recording them where typical script lines are created in Script Editor. And this happens for all the user interface elements in any application including the Finder of course. Finished scripts can then be either applets or folder actions, or menu items in script menu, etc and script menu items can also be specific to an app.

Missing Oneclick,
Keith

While I understand what you’re trying to do, you should be aware that recording is rarely, if ever, the best way to go about this.

The same is true for any script that emulates user actions whether that’s OneClick, AppleScript UI Scripting, QuickKeys, or any other.

The long and the short of it is that UI actions are rarely the best way to achieve something, and AppleScript is at its best when you get right to the heart of the issue.

For example, consider the following pseudo script to open a file that demonstrates the kind of issues:

AppleScript:

tell application "foo"
   open file "Macintosh HD:path:to:file"
end tell

Pseudo actionScript:

tell application "foo"
   click menu item 'open' of menu 'file'
   click disk "Macintosh HD"
   click folder "path"
   click folder 'to"
   click file "file"
   click button "Open"
end tell

OK, it’s an extreme example, but it shows the difference - the second example will be much, much slower - you have to wait for the dialogs to open, screens to draw, etc., wheras the first example just does it.

In my experience recorded scripts ae so far away from usable, portable scripts that you spend more time adjusting the script to your needs than it would have taken to write the script in the first place.

Of course, knowing how to write it ‘the AppleScript Way’ takes experience and practice, but the time spent learning it can pay off many times over.

Check the dictionaries of the applications you’re trying to drive and see if there’s some way to directly achieve the results you’re after.

Thanks for your comments. I agree with your assessment of the differences between recording actions or macros and Applescript. How well the Applescript dictionary covers the application’s environment becomes an issue in being able to script it. As I got more familiar with Applescript, I started to use it more. But when Applescript can’t automate a certain action or whatever, It’s great to have a recording or macro tool that can fill the gaps. The Finder seems to be a mature scripting environment but some apps don’t seem as comprehensive. The number of features and options that are ballooning in certain apps probably need an equal increase in the size of their scripting dictionary. And all it takes is one property left out that you need and your script becomes unfunctional. I would like every action that can be done manually to be either scripted or macroed or the macro can be called within an Applescript. (I just heard that Apple has a new tool in Tiger called Automator. Sounds interesting.)

For example, I want to be able to select the topmost file in a window set to list view that has a number of files in it. The most quick and dirty way I could do this is to use iKey within a larger script as shown below. The script brings a certain folder window to the front or opens it, then iKey selects the topmost file, some variables get info about the file, a new path is set and the file is opened. This script is part of a batch-processing task I’m working on but I’m having a problem converting a Canvas 9 file to an eps one with certain eps options selected. I know there is a better way to batch process files using Applescript but I didn’t like what it did at the time. I haven’t had time to give it a second look.

Have a good day.

tell application “Finder”
activate
open folder “STOCK” of folder “All in progress” of folder “soehn” of folder “Users” of startup disk
end tell
tell application “iKey”
run shortcut “Arrow” of shortcutset “Universal”
run shortcut “Option-arrow” of shortcutset “Universal”
end tell
tell application “Finder”
set the_file to selection as file specification
set file_name to name of the_file
set new_path to “G5HD:Users:soehn:All in progress:” & file_name
open the_file
end tell