{"id":845,"date":"2023-02-05T16:04:27","date_gmt":"2023-02-05T21:04:27","guid":{"rendered":"https:\/\/mfna.org\/rfo\/?p=845"},"modified":"2023-02-05T16:04:27","modified_gmt":"2023-02-05T21:04:27","slug":"has-apple-abandoned-applescript-automator","status":"publish","type":"post","link":"https:\/\/mfna.org\/rfo\/2023\/02\/05\/has-apple-abandoned-applescript-automator\/","title":{"rendered":"Has Apple Abandoned AppleScript?  Automator?"},"content":{"rendered":"<p>Those who know me know that I&#8217;m an Apple Macintosh fan.\u00a0 I was already fascinated with computers when Apple ran their famous &#8220;1984&#8221; commercial<\/p>\n<p><iframe loading=\"lazy\" title=\"Apple 1984 Super Bowl Commercial Introducing Macintosh Computer (HD)\" width=\"584\" height=\"329\" src=\"https:\/\/www.youtube.com\/embed\/2zfqw8nhUwA?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p>and I went, &#8220;Whoa, this I gotta see!&#8221;<\/p>\n<p>Soon after, I acquired an original, first-generation Macintosh, an ImageWriter printer, and I was hooked!<\/p>\n<p>Awed by the rich, well-crafted graphical user interface (GUI), the &#8220;other guys&#8221; were suddenly rocking back on their heels.\u00a0 They had nothing to compare to it.\u00a0 Since Microsoft Windows hadn&#8217;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.<\/p>\n<p>The answer to that complaint arrived in 1987 as Apple introduced Hypercard, the first-ever hypermedia system, pre-dating the worldwide web.\u00a0 Apple pulled the plug on it in 2004 because, as <a href=\"https:\/\/due-diligence.typepad.com\/blog\/2004\/03\/a_eulogy_for_hy.html\" target=\"_blank\" rel=\"noopener\">Tim Oren<\/a> put it, &#8220;HyperCard always had a marketing problem of not being clearly about any one thing.&#8221;\u00a0 In other words, Apple didn&#8217;t know what to do with it.<\/p>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/AppleScript\">AppleScript<\/a> 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 <a href=\"https:\/\/en.wikipedia.org\/wiki\/NeXT\">NeXT<\/a>.\u00a0 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.\u00a0 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).<\/p>\n<p>I remember writing an AppleScript process that would<\/p>\n<ol>\n<li>Mute the sound output of the Mac<\/li>\n<li>Launch an Internet stream recorder every weeknight and point it to a radio broadcast<\/li>\n<li>Turn off the recording two hours later<\/li>\n<li>Save the recording to a folder with a date-time specification<\/li>\n<li>Restore the audio level<\/li>\n<\/ol>\n<p>I could then listen to my replay of the live presentation at a more reasonable hour (for me).\u00a0 Another feature of AppleScript that I enjoyed was the &#8220;folder actions&#8221; ability:\u00a0 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 &#8220;trigger&#8221;).\u00a0 Cool stuff!<\/p>\n<p>Eight years later, Apple added to its set of built-in tools <a href=\"https:\/\/support.apple.com\/guide\/automator\/welcome\/mac\">Automator<\/a>.\u00a0 Building on top of previous capabilities, Automator is designed to create workflows using a point-and-click and drag-and-drop interface.\u00a0 It can call AppleScript scripts and shell scripts, too.<\/p>\n<p>Since my employment entails working with a lot of the &#8220;other guys&#8221; (Windows and Linux), I do a lot of shell scripting and DOS batch\/command files.\u00a0 Microsoft met the Apple challenge in 2006 with <a href=\"https:\/\/en.wikipedia.org\/wiki\/PowerShell\">Windows PowerShell<\/a> (now made open-source and cross-platform in 2016), but I&#8217;ve never taken the time to learn it (every programming language has a learning curve, and I&#8217;m pretty curved out).<\/p>\n<p>Which brings me to the topic of this post.\u00a0 I&#8217;m running the latest (as of this writing) macOS, Ventura (13.2).\u00a0 Apple has made significant changes to its OS under the hood, and in so doing has broken a lot of AppleScripts.\u00a0 A quick <a href=\"https:\/\/duckduckgo.com\/?q=Ventura+AppleScrip\" target=\"_blank\" rel=\"noopener\">Internet search for &#8220;Ventura AppleScript&#8221;<\/a> will reveal page after page of people reporting their AppleScripts no longer work under Ventura.<\/p>\n<p>I have sitting next to me a book I purchased in 1995 by Tom Trinko titled, <a href=\"https:\/\/www.amazon.com\/Applied-Scripting-Technology-Building-Blocks\/dp\/1558283307\/\" target=\"_blank\" rel=\"noopener\">Applied Mac Scripting<\/a>, which focuses on AppleScript, <a href=\"http:\/\/www.userland.com\/\">Userland Frontier<\/a> (now primarily a web scripting language) and some other small automation tools.\u00a0 It&#8217;s a huge book of over 800 pages, and originally came with a CD that has long ago disappeared.\u00a0 I mention this because no one seems to have written anything new about AppleScript in years.\u00a0 The most recent book I could find on <a href=\"https:\/\/www.amazon.com\/Learn-AppleScript-Comprehensive-Scripting-Automation-dp-1430223618\/\" target=\"_blank\" rel=\"noopener\">Amazon<\/a> is dated 2010!\u00a0 Even Apple&#8217;s own Developer site has <a href=\"https:\/\/developer.apple.com\/library\/archive\/documentation\/AppleScript\/Conceptual\/AppleScriptLangGuide\/conceptual\/ASLR_fundamentals.html\" target=\"_blank\" rel=\"noopener\">outdated information on AppleScript<\/a>, and the &#8220;<a href=\"https:\/\/developer.apple.com\/forums\/thread\/3412\" target=\"_blank\" rel=\"noopener\">About AppleScript<\/a>&#8221; forum is locked.\u00a0 That&#8217;s not a good sign.<\/p>\n<p>Here&#8217;s what brought me to this lengthy screed:\u00a0 I like to decorate my Mac&#8217;s &#8220;desktop&#8221; with photos I&#8217;ve taken (or downloaded).\u00a0 I also like to have the image rotated randomly at specific intervals. I save all my photos in a folder (<em>not<\/em> my Pictures folder).\u00a0 Over the years, I have tried a number of programs that purport to do this, and all fail to meet 100% of my requirements.\u00a0 The one I&#8217;ve used for years is a little freeware program, Change Desktop by Brian Bergstrand (hat tip!), now unavailable.\u00a0 So, I thought I&#8217;d write one myself.\u00a0 After all, I have all the tools necessary, don&#8217;t I?<\/p>\n<p>As a proof of concept, I quickly whipped up a shell script.\u00a0 It simply reads through the folder, building an array of file names, chooses one at random then displays the filename.\u00a0 This is the script:<\/p>\n<blockquote><p><code>#!\/bin\/zsh<br \/>\n<em>#<\/em><br \/>\n<em>unset p<\/em><br \/>\n<em>let x=1<\/em><br \/>\n<em>#<\/em><br \/>\n<em>for f in *;<\/em><br \/>\n<em>do<\/em><br \/>\n<em>if [ -f \"$f\" ] ; then<\/em><br \/>\n<em>p[$x]=\"$f\";<\/em><br \/>\n<em>let x=x+1<\/em><br \/>\n<em>else<\/em><br \/>\n<em>echo \"$f\" is not a file<\/em><br \/>\n<em>fi;<\/em><br \/>\n<em>done;<\/em><br \/>\n<em>RANDNUM=$(( 1 + $RANDOM % $x ))<\/em><br \/>\n<em>echo \"There are $x files\"<\/em><br \/>\n<em>FN=${p[$RANDNUM]}<\/em><br \/>\n<em>echo \"The randomly chosen file is $FN\"<\/em><\/code><\/p><\/blockquote>\n<p>Okay, it works.\u00a0 But the shell doesn&#8217;t provide a way (that I know of) to set the desktop image.\u00a0 I found several AppleScripts that should do the same thing.\u00a0 But they don&#8217;t.\u00a0 They either throw an error (AppleScript&#8217;s errors are as unfriendly as any programming language&#8217;s I&#8217;ve seen) or they don&#8217;t take the right image from the folder specified.\u00a0 Huh?<\/p>\n<p>Automator seems now to be Apple&#8217;s preferred method of creating your own workflows (which is the name Apple gives the processes you create).\u00a0 At least they&#8217;ve <a href=\"https:\/\/support.apple.com\/guide\/automator\/create-a-workflow-aut7cac58839\/2.10\/mac\/13.0\">updated the documentation<\/a> for it.\u00a0 I&#8217;ve created Automator workflows, but they don&#8217;t seem as &#8220;intuitive&#8221; as AppleScript.\u00a0 Well, as AppleScript used to be.\u00a0 As is the case with most software, &#8220;feature creep&#8221; 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.<\/p>\n<p>Pity.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Those who know me know that I&#8217;m an Apple Macintosh fan.\u00a0 I was already fascinated with computers when Apple ran their famous &#8220;1984&#8221; commercial and I went, &#8220;Whoa, this I gotta see!&#8221; Soon after, I acquired an original, first-generation Macintosh, &hellip; <a href=\"https:\/\/mfna.org\/rfo\/2023\/02\/05\/has-apple-abandoned-applescript-automator\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,5],"tags":[],"class_list":["post-845","post","type-post","status-publish","format-standard","hentry","category-technology","category-apple"],"_links":{"self":[{"href":"https:\/\/mfna.org\/rfo\/wp-json\/wp\/v2\/posts\/845","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mfna.org\/rfo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mfna.org\/rfo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mfna.org\/rfo\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mfna.org\/rfo\/wp-json\/wp\/v2\/comments?post=845"}],"version-history":[{"count":4,"href":"https:\/\/mfna.org\/rfo\/wp-json\/wp\/v2\/posts\/845\/revisions"}],"predecessor-version":[{"id":849,"href":"https:\/\/mfna.org\/rfo\/wp-json\/wp\/v2\/posts\/845\/revisions\/849"}],"wp:attachment":[{"href":"https:\/\/mfna.org\/rfo\/wp-json\/wp\/v2\/media?parent=845"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mfna.org\/rfo\/wp-json\/wp\/v2\/categories?post=845"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mfna.org\/rfo\/wp-json\/wp\/v2\/tags?post=845"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}