Those who know me know that I’m an Apple Macintosh fan. I was already fascinated with computers when Apple ran their famous “1984” commercial
and I went, “Whoa, this I gotta see!”
Soon after, I acquired an original, first-generation Macintosh, an ImageWriter printer, and I was hooked!
Awed by the rich, well-crafted graphical user interface (GUI), the “other guys” were suddenly rocking back on their heels. They had nothing to compare to it. Since Microsoft Windows hadn’t yet made an appearance, the best argument against the Mac came in the form of the criticism that the Mac had no command line, and no way for the average user to create their own programs, processes and workflows.
The answer to that complaint arrived in 1987 as Apple introduced Hypercard, the first-ever hypermedia system, pre-dating the worldwide web. Apple pulled the plug on it in 2004 because, as Tim Oren put it, “HyperCard always had a marketing problem of not being clearly about any one thing.” In other words, Apple didn’t know what to do with it.
AppleScript made its debut in 1993, when Apple was still shipping System 7, the operating system that was replaced by Steve Jobs when he returned to Apple from NeXT. Compared to the DOS command line scripting language, AppleScript was not only fluid, very English-like in its syntax and language structure, but also leveraged components of the Mac operating system down to its core. Scripts could be written to automate tasks, could integrate with other scripting languages (the porting of NextStep to the Mac and integrating it with the classic Mac OS added the ability to write Unix shell scripts).
I remember writing an AppleScript process that would
- Mute the sound output of the Mac
- Launch an Internet stream recorder every weeknight and point it to a radio broadcast
- Turn off the recording two hours later
- Save the recording to a folder with a date-time specification
- Restore the audio level
I could then listen to my replay of the live presentation at a more reasonable hour (for me). Another feature of AppleScript that I enjoyed was the “folder actions” ability: Write a script that watches a given folder and when an item is added, changed or removed, the script would take an action (in database parlance this is known as a “trigger”). Cool stuff!
Eight years later, Apple added to its set of built-in tools Automator. Building on top of previous capabilities, Automator is designed to create workflows using a point-and-click and drag-and-drop interface. It can call AppleScript scripts and shell scripts, too.
Since my employment entails working with a lot of the “other guys” (Windows and Linux), I do a lot of shell scripting and DOS batch/command files. Microsoft met the Apple challenge in 2006 with Windows PowerShell (now made open-source and cross-platform in 2016), but I’ve never taken the time to learn it (every programming language has a learning curve, and I’m pretty curved out).
Which brings me to the topic of this post. I’m running the latest (as of this writing) macOS, Ventura (13.2). Apple has made significant changes to its OS under the hood, and in so doing has broken a lot of AppleScripts. A quick Internet search for “Ventura AppleScript” will reveal page after page of people reporting their AppleScripts no longer work under Ventura.
I have sitting next to me a book I purchased in 1995 by Tom Trinko titled, Applied Mac Scripting, which focuses on AppleScript, Userland Frontier (now primarily a web scripting language) and some other small automation tools. It’s a huge book of over 800 pages, and originally came with a CD that has long ago disappeared. I mention this because no one seems to have written anything new about AppleScript in years. The most recent book I could find on Amazon is dated 2010! Even Apple’s own Developer site has outdated information on AppleScript, and the “About AppleScript” forum is locked. That’s not a good sign.
Here’s what brought me to this lengthy screed: I like to decorate my Mac’s “desktop” with photos I’ve taken (or downloaded). I also like to have the image rotated randomly at specific intervals. I save all my photos in a folder (not my Pictures folder). Over the years, I have tried a number of programs that purport to do this, and all fail to meet 100% of my requirements. The one I’ve used for years is a little freeware program, Change Desktop by Brian Bergstrand (hat tip!), now unavailable. So, I thought I’d write one myself. After all, I have all the tools necessary, don’t I?
As a proof of concept, I quickly whipped up a shell script. It simply reads through the folder, building an array of file names, chooses one at random then displays the filename. This is the script:
for f in *;
if [ -f "$f" ] ; then
echo "$f" is not a file
RANDNUM=$(( 1 + $RANDOM % $x ))
echo "There are $x files"
echo "The randomly chosen file is $FN"
Okay, it works. But the shell doesn’t provide a way (that I know of) to set the desktop image. I found several AppleScripts that should do the same thing. But they don’t. They either throw an error (AppleScript’s errors are as unfriendly as any programming language’s I’ve seen) or they don’t take the right image from the folder specified. Huh?
Automator seems now to be Apple’s preferred method of creating your own workflows (which is the name Apple gives the processes you create). At least they’ve updated the documentation for it. I’ve created Automator workflows, but they don’t seem as “intuitive” as AppleScript. Well, as AppleScript used to be. As is the case with most software, “feature creep” enters the picture and what was once a simply, handy tool (like HyperCard) gets burdened down with external functions, libraries, frameworks and no longer is accessible to the common man.