

The second step takes the resulting array return, and appends it to the end of the current draft. Should the draft happen to be empty, it will prompt you to enter text to be converted. The first step runs an AppleScript step that converts the contents of the current draft into phonetic words. In some cases, it will also do something that’s very easy in AppleScript, but not so much in JavaScript but the main point is that I wanted to use something that was relatively easy to follow, and was not dependent upon any additional third party apps. In each case, the translated content will be returned to Drafts. In each case the AppleScript will translate the content it is passed to NATO phonetic alphabet. Throughout this post I’m going to use an example script as the basis for showing you how this works. This result is available within subsequent (JavaScript) Script action steps as an array, accessed using context.appleScriptResponses.

You can also return a result from the AppleScript allowing you to process the draft contents outside of Drafts and return a result. On execute ( draft ) - Your main script goes here end execute Since it will always be passed the draft object, you should always include this too. The script is based around a subroutine called execute, and so the step should always contain a subroutine of that name. If you don’t have Late Night Software’s Script Debugger app for AppleScript, go and get it right now, then come straight back. and so the general recommendation, that I fully support, is to write your AppleScript in another editor and then paste it in. two clicks and a new window), it doesn’t have any syntax highlighting, validation, etc. While it’s even easier to add AppleScript than it is to add JavaScript to the action (one click and field entry vs. You can simply add A new AppleScript action step and then add the AppleScript content to the action. Probably the simplest way to add AppleScript to your Drafts actions is via the new AppleScript action. This is just to comply with the macOS security requirements and is necessary because to run any of the local scripts, Drafts will need to temporarily create script files on the file system to enable them to be run. This is normal and you should just be prompted once. I’ll probably cover more on this in a future post, but I will touch on this later as it also opens up a useful opportunity with AppleScript.Īs a note, not of warning, but more for awareness, you will notice that when you run your first local script-related action, you are prompted to permit access for Drafts to its script directory (at ~/Library/Application Scripts/-OSX). The release also includes support for running shell scripts so you can utilise Zsh, Bash, Perl, Ruby, Python, etc. As noted, it is limited right now, only allowing you to create drafts, and it isn’t something I’m going to cover in this post.

Thus allowing you to control Drafts from AppleScript outside of the app. In this post I’m going to specifically cover the triggering of AppleScript from within the Drafts actions framework.īut in this release, Greg also included limited AppleScript support for Drafts itself. This latest version of Drafts includes several key new features, of which AppleScript support is just one.

In the latest release (version 19) of the app on macOS, developer Greg Pierce (aka AgileTortoise) has significantly extended the automation and processing scope through the addition of AppleScript, and in this post I’m going to walk you through some example set-ups related to this. It provides a quick point of capture and powerful tools to let me do more with the text to prepare and send it to its final destination than any other app possible could and that says a lot when you look at apps like Keyboard Maestro, Text Soap and Sublime Text! As the tag line says this is the app where text starts, and that’s certainly true of my use cases. To say I’m a daily user would not do justice to the app. Drafts is utilitarian text app available on iOS, iPadOS, and macOS that I use frequently.
