{"id":484,"date":"2022-01-24T11:01:40","date_gmt":"2022-01-24T19:01:40","guid":{"rendered":"https:\/\/icanthascheezburger.com\/wordpress\/?p=484"},"modified":"2022-01-24T11:43:50","modified_gmt":"2022-01-24T19:43:50","slug":"swiftscript","status":"publish","type":"post","link":"https:\/\/icanthascheezburger.com\/wordpress\/2022\/01\/swiftscript\/","title":{"rendered":"SwiftScript"},"content":{"rendered":"<p>This is longer than a tweet would be so instead of making a Twitter thread that\u2019s super annoying that you have to scroll through, I\u2019ll make an actual blog post like a gentleman.<\/p>\n<p>I have a free idea for Apple: SwiftScript.<\/p>\n<p>It\u2019s the successor to AppleScript. It doesn\u2019t replace Shortcuts, but it\u2019s what you graduate to after you outgrow Shortcuts.<\/p>\n<h2 id=\"thebasics\">the basics<\/h2>\n<p>(note: I\u2019m describing this in present tense like it exist, but it doesn\u2019t. I\u2019m sorry, I don\u2019t mean to get you all excited over nothing; it\u2019s just easier to describe it that way instead of constantly with qualifiers)<\/p>\n<p>It\u2019s an actual programming language. It can look Swift-like. Hell, it could even be Swift. I\u2019m not really digging into details here; I just want to do broad strokes.<\/p>\n<p>AppleScript is an actual programming language too, but SwiftScript drops the cutesy English-like syntax which always sounded great on paper but is a nightmare in practice. Instead, we make SwiftScript really easy and approachable by making everything <em>super<\/em> discoverable.<\/p>\n<p>Unlike the AppleScript editor which is basically just an empty editor you type text into and click \u201cRun,\u201d hoping for the best, SwiftScript is always meant to be interacted with by offering a REPL. You are constantly expected to dig around with this REPL and figure out what\u2019s what in the language and in the apps you want to automate. Everything you type is very much autocompleted, and things are strongly typed so that the SwiftScript environment can always tell you what a thing is, and what you can do with that thing.<\/p>\n<p>You know how web browsers have inspectors that let you click on any element in a page and see it in the DOM? The SwiftScript inspector can let you do the same, except with all the applications on your device. You can look at the Mail app and click a message in the message list and it\u2019ll tell you about the Message entity, what fields a message has, and what methods you can call on the message. Clicking on the Search box will show you related objects, like an object to construct a search for messages. No guessing at what something is called or poring through docs you don\u2019t quite understand. You see something you want to automate, and SwiftScript will show you what you\u2019re dealing with.<\/p>\n<p>Now, for this to be useful, we have to make apps that have very rich SwiftScript libraries for the scripts to use.<\/p>\n<p>What I mean here is that when an app supports SwiftScript, every single entity in the app exposes a SwiftScript API. Shortcuts has been a cool thing to see in iOS (and now the Mac) but far too often I find myself wanting to automate something only to find that it just can\u2019t be done because there isn\u2019t anything close to resembling an action for it. SwiftScript won\u2019t be limited like that; as a programmer you\u2019ll be able to programmatically do virtually anything you can manually do as a user.<\/p>\n<h2 id=\"goingpastjustascriptinglanguage\">going past just a scripting language<\/h2>\n<p>So far, the SwiftScript I\u2019ve described is fundamentally a nicer AppleScript, mostly predicated on the idea that you invoke a script, and then run it.<\/p>\n<p>But SwiftScript can do more. SwiftScript apps can offer hooks throughout the app where SwiftScript scripts you write can act automatically when those hooks happen.<\/p>\n<p>For instance, Mail might offer a hook for a new message coming into the Resumes folder (a folder which gets populated by a filter, perhaps). You might then make a SwiftScript that watches for this event, and then whenever a message of this sort comes in, it searches the message for the resume attachment, saves that file to a designated folder, then creates a to-do item in OmniFocus directing you to review that resume complete with the name of the applicant (from the From field), a link to the file itself, and a link back to the original Mail message.<\/p>\n<p>Then, you might add another script that watches for replies to messages, and if you\u2019re replying to a message in the Resumes folder, and then it will present you with a small GUI that asks you whether you are moving forward with that applicant or not, and based on that response, fills out a message for you with the appropriate details supplied from a template, with fields that you can fill in with the right added information. If we want to get really elaborate, maybe when you email a candidate you want to interview, the email might even include a few options for interview times in the coming days based on your availability in the time you blocked off in the afternoons for interviews.<\/p>\n<p>But SwiftScript goes beyond just the applications\u2019 APIs and the hooks they can provide. SwiftScript also is a powerful general-purpose programing language in its own right, with access to super powerful libraries. So not only can you perform repetitive tasks, the kinds of tasks you can let the computer perform can get increasingly sophisticated.<\/p>\n<p>For instance, you might make a script that fires when you favorite a tweet in Twitter, and then the script will save that tweet\u2019s contents to a database. A lot of tweets\u2019 contents are just an image of text, so your SwiftScript can check to see if the tweet includes images, and if it does, check the image to see if it\u2019s text, and if so, OCR the image and save that text into the database so that it\u2019s easily searchable later.<\/p>\n<p>You could even watch that text for certain key words and then tag that tweet in your database if appropriate.<\/p>\n<h2 id=\"apple:pleasetakethisideaandrunwithit\">apple: please take this idea and run with it!<\/h2>\n<p>The thing that\u2019s just beautiful about SwiftScript here is that it turns any user into an application developer. But you don\u2019t have to know how to develop a full application yourself; you really just get the power of all the apps you already have, but SwiftScript is there to help you fill in the gaps.<\/p>\n<p>It\u2019s clear that Apple looked at its automation story and saw that although AppleScript is quite powerful and continues to have a cult following (think of how amazing it is that AppleScript actually made the jump from classic MacOS to OS X and it\u2019s still around and even works with Shortcuts), they saw a product that\u2019s too complex, and decided that the future of automation on Apple platforms had to be not just made easier to user, but watered down.<\/p>\n<p>I\u2019m so glad that Shortcuts is a thing, and I\u2019m glad that it\u2019s energizing people about automation on their Macs and iOS devices. But it\u2019s <em>less capable<\/em> than AppleScript.<\/p>\n<p>SwiftScript tries to fundamentally change what automation means to you as a user. It\u2019s an advanced tool because it\u2019s a programming language but it\u2019s making programming highly approachable by being an exploratory language that you are meant to tinker with at runtime as you build your scripts. It\u2019s still for that sophisticated user, but it has the potential to give that user massive leverage by putting programming-shaped handles on every aspect of their computer. I\u2019d love to live in the alternate universe where Apple built this.<\/p>\n<p>But I guess building a car is cool too.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is longer than a tweet would be so instead of making a Twitter thread that\u2019s super annoying that you have to scroll through, I\u2019ll make an actual blog post like a gentleman. I have a free idea for Apple: SwiftScript. It\u2019s the successor to AppleScript. It doesn\u2019t replace Shortcuts, but it\u2019s what you graduate [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[],"class_list":["post-484","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/icanthascheezburger.com\/wordpress\/wp-json\/wp\/v2\/posts\/484","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/icanthascheezburger.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/icanthascheezburger.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/icanthascheezburger.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/icanthascheezburger.com\/wordpress\/wp-json\/wp\/v2\/comments?post=484"}],"version-history":[{"count":0,"href":"https:\/\/icanthascheezburger.com\/wordpress\/wp-json\/wp\/v2\/posts\/484\/revisions"}],"wp:attachment":[{"href":"https:\/\/icanthascheezburger.com\/wordpress\/wp-json\/wp\/v2\/media?parent=484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/icanthascheezburger.com\/wordpress\/wp-json\/wp\/v2\/categories?post=484"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/icanthascheezburger.com\/wordpress\/wp-json\/wp\/v2\/tags?post=484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}