[PSA] native AppleScripting support for Swift

Hi folks,


(Tried to post this yesterday, but it got stuck in the mod queue due to containing links so I'm reposting it with URLs mangled; de-mangle as needed.)


In light of OS X 10.11 addressing some longstanding deficiencies in NSAppleEventDescriptor, I've been dusting off a fork of my old objc-appscript project, now renamed AppleEventBridge, modernizing and extending it both to take advantage of improvements to ObjC in the last few years and to add native support for Apple's new Swift language:


  hxxps://bitbucket.org/hhas/appleeventbridge/


Unlike Apple's flawed Scripting Bridge and JavaScript for Automation, AEB aims to provide application scripting capabilities and compatibility that equal (if not better) AppleScript's own, along with superior documentation and developer tool support.


Here's a simple example, comparing AEB's new Swift and ObjC bindings against de facto standard AppleScript:


  tell application "TextEdit" to get text of document 1


  let result = try TextEdit().documents[1].text.get() as! String


  id result = [[TEDApplication application].documents[1].text getItem];



A simple Apple event translation tool, SwiftAETranslate, is included in the project, making it easy to convert AppleScript commands to their Swift equivalents. It's a great learning tool if you've always found AppleScript code perplexing, and well worth pulling the project just to try it out yourself:


    git clone hxxps://bitbucket.org/hhas/appleeventbridge.git



Swift support requires Swift 2.0 and Xcode 7 beta 3 or later, and works on 10.10+.


While this release is not intended for production use (builds are rather messy and there's still rough edges and bugs), it is sufficiently mature to allow interested Swift and ObjC users to explore and experiment with it, and to offer advice, suggestions, and other feedback with a view to getting the whole thing to a production-quality 1.0 release before the end of the year.



Enjoy, and I look forward to hearing what you think.

Wow!! Thrilled to see that you are working on this again. I was devastated that you had to stop development on the original AppScript.

I'm going to check this out as soon as I get home.


This is a great day for Apple developers. Looking forward to vesion 1.0!

It indicates this project is no longer developed or supported. 😟 Do we have any other alternative?

SwiftAutomation (bitbucket.org/hhas/swiftae) is a *native* Swift-AppleEvent bridge I wrote once it became clear Apple weren't into ObjC any more and Swift was the hot new place to be at. SA also has a much cleaner, simpler design and fully integrates with Swift's static type system. Hence the retirement of AEB.


Progress-wise the implementation's all there, but the documentation's a real mess, it lacks a proper test suite, and it hasn't seen much real-world use to date, so there may be bugs. I started putting together a minimal 'SwiftEditor' app (bitbucket.org/hhas/swiftautoedit) with dictionary viewer and AS-to-Swift command translator tools, but haven't had any time to polish or package it up properly. Individual pull requests are always welcome, but TBH unless the Swift community and/or Apple want to step up and back the project I can't put any significant time into it myself. (I'm bootstrapping my own automation company right now so really don't need to be tilting at windmills.)


One more thing: Apple disbanded the Mac Automation team and fired its Product Manager at end of 2016, I'm not hopeful for the long-term future of AppleScript, Apple event IPC, or anything else in the extant Mac Automation stack. I did encourage users last year to file Radar reports (e.g. openradar.appspot.com/29332915), but Apple haven't responded to those or shown any interest as far as I'm aware. So the standard caveat emptors apply.


...


p.s. I recently did a quick port to Node.js (bitbucket.org/hhas/nodeautomation); it's not quite finished, but is basically what JavaScript for Automation *should* have been instead of the botched POS abandonware that Apple shoved out in 10.10 and promptly forgot. (Node has millions of established users, the biggest library repository in the world, copious editors and other tools, and impressive year-on-year growth.) Again, if folks want to take it and run with it I'll give them my support.

[PSA] native AppleScripting support for Swift
 
 
Q