Getting around to AppleScript integration in the Mac version. Interested in feedback from those who might make use of this feature. This is not about Drafts itself being scriptable (which is coming as well), but about how a “Run AppleScript” action step should behave when calling AppleScripts. I’m going to provide a few suggested directions I could go with this and would like comments, or suggestions if the technically inclined can think of a better option I’m missing.
A Few Background Details
Drafts is a sandboxed app. As a result, the only external scripts the app is permitted to execute must reside in its designated scripts folder in ~/Library/Application Scripts/
. So, to run an AppleScript, it must be in a file in that folder.
By default, a sandboxed app only has permissions to read from it’s own Application Scripts
folder, but it can prompt the user for write permissions to that folder like any other folder it it needs to write a file there.
AppleScripts (and other OSA-compliant scripts) are compiled and stored in a binary format, not as plain text scripts. Because of the tooling to compile and test scripts, it makes the most sense for users to edit those scripts in the Script Editor app included with the Mac, not directly in Drafts or another text editor.
Implementation Options
There’s a few different ways I could approach how the “Run AppleScript” action step would run scripts. These are the options I’ve thought of so far and am interested on which sounds most appealing. There are probably some pros and cons of each approach I’ve not yet considered as well.
Option #1: You manage the AppleScript files
A “Run AppleScript” step would just store the relative path of a script file, and when executed, attempt to find the script by that name in the file system and run it.
- Pros:
- I don’t have to implement much to support it!
- Scripts would be stored compiled, ready to edit in the file system. Nothing is required in Drafts to pickup on changes to a script file.
- Requires no special permission to write to the
Application Scripts
directory.
- Cons:
- Scripts are not backed up, or synced between Macs. If you run Drafts on multiple Macs (or multiple user accounts on same Mac), you would be responsible for moving around and updating and scripts you need. Same for a re-install of Drafts on a new system.
- Not portable. An action requiring an AppleScript could not simply be shared via the Action Directory, export, or other means without also directing users how how to acquire and install the scripts it requires.
- No visibility of script content within Drafts.
Option #2: Drafts stores the scripts in binary format
When editing a a “Run AppleScript” step, the user can import a script file (from anywhere on their system) they have written and compiled in Script Editor. The binary “.scpt” file data would be stored in the action, and when the action is run, Drafts would save that data out to disk in a temp folder in the Application Scripts
directory and execute it.
- Pros:
- Scripts would be stored compiled and ready to run.
- Portable. Scripts would be part of the action data, and synced and backed up to iCloud and be shareable via the Action Directory and/or export mechanisms.
- Cons:
- Requires special permission to write to the
Application Scripts
directory. - No visibility of script content within Drafts.
- Changes to the script would require it be re-imported into Drafts.
- Requires special permission to write to the
Option #3: Drafts stores the scripts in plain text format
The plain text version of the AppleScript would be stored in Drafts. It could be previewed and edited in Drafts directly, much like Javascript is now.
- Pros:
- Visibility. Users could read/preview script contents in Drafts, in the action directory, etc., before running the action.
- Portable. Scripts would be part of the action data, and synced and backed up to iCloud and be shareable via the Action Directory and/or export mechanisms.
- Cons:
- Requires special permission to write to the
Application Scripts
directory. - Maybe slow(?). Likely caching of compiled versions would be possible, but also might require the script to be compiled before running each time.
- Drafts action manager is not the idea environment to edit/test scripts.
- Requires special permission to write to the
Conclusion
Thoughts on which of these options seem most attractive? Ideas for other approaches?