If the Mac is to be the computer for the rest of us, it also needs to give access to more advanced controls by scripting its actions. This article traces some of the more significant attempts to bring scripting to the rest of us.
Over the last forty years there have been dozens of programming and scripting languages that have been developed for, or ported to, Mac OS. The great majority have had no pretensions of use by regular users. The first intended to be used by anyone and everyone was HyperTalk, released three years after the original Mac.
HyperTalk (1987)
Apple’s hypertext authoring environment HyperCard contained its own scripting language HyperTalk. For many of those who built brilliant HyperCard stacks, this new scripting language was the first programming language they had used. Sadly, although seriously cool in its day, HyperTalk was both limited and limiting, as most came to discover.
If you’ve written AppleScript, HyperTalk has a distinct familiarity in its informal language, often mistakenly claimed to resemble normal English. This code snippet illustrates that: on mouseUp
put the value of card field "age" into theAge
end mouseUp
HyperTalk spawned many imitators, and some like SuperCard went on to outlive it, but by 2000 HyperCard and HyperTalk were all but dead.
UserTalk (1988-92)
In 1988, Dave Winer started developing a scripting language that became UserTalk in Frontier, released in 1992. Built around an object database, Winer took his early work to Apple. In 1988-89, Jean-Louis Gassee, then president of Apple Products Division, announced the formation of a HyperTalk Standards Committee to develop a scripting language, and Apple agreed with Winer that they would each develop their own mutually compatible scripting systems.
After Apple’s release of AppleScript, Frontier’s UserTalk declined in popularity. By 1994, Winer was burnt out, and the following year Frontier moved on to become a cross-platform Web content management system.
AppleScript (1988-93)
In some respects a successor to HyperTalk, AppleScript was released in October 1993, with System 7 Pro version 7.1.1. Despite all the odds, and several determined attempts to strangle it, it’s still supported in macOS Sequoia.
The concept behind AppleScript is simple: scripts that compile to a series of instructions for dispatch by macOS to their destination application, which in turn is controlled by those commands to perform a co-ordinated sequence of functions. At their simplest, these can open a document and print it, for instance. At their most complex, they can automate intricate and repetitive tasks that are messy in a GUI.
As a minimum, every application supports a core of commands to play clean with the Finder and macOS. Those, and the suites of additional commands that bring joy to the scripter, are documented in standard formats within each application’s dictionary, which can be browsed by the bundled Script Editor and other tools. Rather than having to locate additional documentation sets specific to each application, all a scripter should need to do is open the dictionary.
Complexity comes because AppleScript is in fact an object-oriented language as sophisticated as Objective-C; don’t be deceived by its apparently relaxed and informal style, with examples such as tell application "System Events"
set mailIsRunning to application process "Mail" exists
end tell
if mailIsRunning then
-- do one thing
else
-- do another thing
end if
You might use that code to set up a script that interacts with the Mail app. It first asks macOS whether it knows that Mail is running, and depending on the answer it executes the code that you insert where the comments (prefaced by ‘--‘ characters) are placed. Unlike the majority of programming languages, punctuation marks are used sparsely in AppleScript, making it considerably easier to write code that works, rather than tripping over a missing semicolon.
When ready to test your script, it compiles into intermediate code, and the editor automatically checks, formats and colours your source code, reporting any errors that it finds. When run, the intermediate code works through macOS to fire off AppleEvents (AEvents) to trigger the target applications to perform the actions.
For the more serious AppleScript coder bundled support was too limited, and it was the arrival of Mark Alldritt’s Script Debugger in late 1994 that unleashed its full power. Sadly, Script Debugger is retiring this year after over 30 years of innovative development.
Although AppleScript was integrated into Apple’s Xcode as AppleScript Studio, in recent years it has been left to languish, with occasional rumours of its demise.
Prograph (1982-89)
In 1989, the visual programming language Prograph was launched on the Mac. Sometimes described as a dataflow language, and thoroughly object-oriented, it won awards, was ported to Windows in the late 1990s, but was last seen running as Marten.
In this example method, data flows from the top to the bottom. Normally terminals on the top ‘shelf’ of the method diagram represent the inputs to that method. Data then flows from the top shelf through the intermediate processes, until it reaches the bottom. If there are outputs from the method, they are gathered by connections made to terminals on the bottom ‘shelf’ in the method. Order of execution is not prescribed, and can take place whenever data is available; this allows for inherent concurrency, and the potential to exploit multiprocessor systems without the need for language primitives.
Shell scripts (2001)
With the advent of Mac OS X 10.0 Cheetah came Terminal and shell scripts, inherited from NeXTSTEP. Although powerful and popular with those who prefer this Unix-based approach, they have predictably had limited impact on the regular user wanting to script actions on their Mac.
Automator (2002-05)
Even ‘natural’ programming languages like AppleScript have to be learned, a task that many find too verbal and mechanical. Recognising this, Apple introduced Automator in OS X 10.4 in 2005 to produce custom workflows and apps using more intuitive visual tools.
Although often assumed to be a development of AppleScript, apart from its ability to run AppleScript objects, Automator is very different. Instead of relying on AppleEvents and dictionaries, Automator’s modular actions are separate code objects installed in the Automator folder in a Library folder. macOS comes with a huge free library of actions that can accomplish tasks you might pay good money for, so familiarity can save cost.
Automator is highly extensible, as its actions can include both AppleScript code and Terminal shell scripts. Thus if you cannot find a standard action to do what you want, if it can be expressed in a suitable script, you can build that into your workflow. Nevertheless, in 2021 Apple announced that Automator was to be succeeded by Shortcuts.
Swift Playgrounds (2014-16)
From the early days of the Mac, Apple has invested in programming languages designed to make best use of its APIs. In Classic times, that was Object Pascal, and its open-source class library MacApp. In 2014, Apple released a new language intended to be the preferred choice across all its platforms, Swift. From those early days, Swift has had an interactive mode, based on the read-eval-print loop (REPL) popularised by Lisp. This versatility has been developed in Swift Playgrounds, recently renamed in the singular, both within Xcode and as a standalone app targeted at those learning to code for the first time.
As an introduction to Swift in education, this has been impressive, but it hasn’t yet proved a gateway for those who didn’t really want to learn how to use Xcode in the first place.
Shortcuts (2014-21)
Shortcuts started out in the winter of 2014-15 as Workflow by DeskConnect. Apple bought it in 2017, and it became Shortcuts the following year, when it was integrated into Siri in iOS 12. Its arrival in macOS 12 was announced at WWDC in 2021, as Automator’s intended successor.
While Shortcuts on macOS can run AppleScript and shell scripts, the mechanisms involved in Shortcuts’ actions are completely different from AppleScript and Automator. For an app to support all three well requires it to present four different interfaces: one for the user in the GUI, AppleEvents for AppleScript, Automator actions, and now Shortcuts actions.
While Shortcuts has attracted quite a following, particularly in iOS and iPadOS where it’s the first real scripting environment, its impact in macOS has so far been limited. Like all its predecessors, it still hasn’t brought scripting to the rest of us.
Credits
HyperTalk: Dan Winkler
UserTalk: Dave Winer and Doug Baron
AppleScript: William R Cook and many others
Script Debugger: Mark Alldritt and Shane Stanley
Prograph: Tomasz Pietrzykowski, Jim Laskey and others
Automator: Sal Soghoian and other Apple engineers
Swift Playgrounds: Chris Lattner, Doug Gregor, John McCall, Ted Kremenek, Joe Groff and others
Shortcuts: Ari Weinstein, Conrad Kramer and Nick Frey
一週裡有一半時間都坐在這裡工作 / I spend half of the time in a week working here / 私は一週間の半分の時間をここで働いています我讓店裡特意給我保留的專用裂口杯 / I asked the store to keep a special slit cup for me / 私は店に特別なスリットカップを取っておいてもらった
I was originally notified that I had to meet with a client in the morning, but when I rode to the place where I usually park, I was told that it was not going to happen. Because I got up earlier than usual, I felt a little sleepy. So, I sat in the shop and meditated for five minutes, and took a couple of sips of caffeine to get some blood back.
在最近幾次冥想的過程中發現,Apple Watch 的這個呼吸頻率對我來說已經偏快了,如果完全按照我自己的節奏來控制,起碼得是 3 次,或者 2.5 次這個頻率,但 Apple Watch 已經不能設置更慢的呼吸節奏了。
I found out in the last few meditations that this breathing rate of Apple Watch is too fast for me. If I completely control it according to my own rhythm, it should be at least 3 times, or 2.5 times this frequency, but Apple Watch can no longer set a slower breathing rhythm.
剛才測了一下時間,我三次呼吸(一呼一吸)的總時長是 2:03 (兩分零三秒)。這樣的話,換成 AW 的呼吸頻率計算方式應該是「每分鐘呼吸 1.5 次」。
I just measured the time and found that the total duration of my three breaths (one inhale and one exhale) was 2:03 (two minutes and three seconds). In this case, using AW’s breathing frequency calculation method, it should be “1.5 breaths per minute”.
*The English and Japanese translations are done by New Bing’s AI.
*以上の英語と日本語の翻訳は、New Bing の AI によって行われました。
但是,翻譯完之後,它居然一直反問我新的問題,是對我和我的行為感到好奇嗎?
But after translating, it kept asking me new questions. Is it curious about me and my behavior?
しかし、翻訳した後、新しい質問をずっと聞いてきました。私と私の行動に興味があるのでしょうか?
不是的。據我所知,它只是一個根據字詞關係來生成對話的超大模型,這種對話其實非常可能來自人類語庫中不要讓話掉在地上的社交禮貌用例。所以,這種反問並不能證明這個對話 AI 已經具備了意識。
No. As far as I know, it is just a huge model that generates dialogue based on word relationships. This kind of dialogue is very likely to come from human language libraries that do not want to let the conversation fall to the ground. Therefore, this kind of rhetorical question cannot prove that this dialogue AI already has consciousness.
いいえ。私の知る限り、それは単に単語の関係に基づいて対話を生成する巨大なモデルです。このような対話は、会話を地面に落とさないようにする人間の言語ライブラリから非常に可能性が高く来ています。したがって、このような反語的な質問は、この対話 AI がすでに意識を持っていることを証明できません。