Send Text and an Action to Drafts for iOS From the Command Line

Tweet This Post

I am very much a newbie at bash scripting in Terminal, but I felt tempted to replicate the tool I built at TaskPusher for the command line: namely to send text and an optional action to Drafts from a Mac OS computer.

TaskPusher is a PHP web application that sends an url-encoded string to Pushover, a notifications app for iOS. Pushover already provided the code to send notifications from the Unix command line so I only had to make a few modifications to send a message to Drafts.

Before we begin, I need to qualify that I literally have only started bash scripting this week, so please bear with me if there are any inefficiencies or errors. The script works, but if you have any suggestions please comment below in the Disqus widget or send me a tweet.

The first challenge is that all the text after the Drafts URL scheme drafts:///create?text= needs to be url-encoded. I found a basic sed find/replace script here and I copied the code snippet into this gist:



Just add this in a text file somewhere in your directory and call it urlencode.sed. I haven't gotten to move new scripts into /usr/local/bin (or what-have-you) so in the pushover script below you will have to precede urlencode.sed with the directory path. In my working script I replace it with ~/j/scripts/urlencode.sed.

I named the following script pushover but you can call it whatever you want:



How to Run the Script

If you haven't already, purchase Pushover in the app store, create an account and get your user key. Then create an app in Pushover and save the API token. Where it says $APP_TOKEN and $USER_KEY enter yours in the script.

Now go to Terminal. You need to set one or two variables to send to Drafts: the message and the action. The message is the actual text of your draft. The action is the exact wording of any of the actions in the Action Directory. For example, I may want to send text to Due: 6pm pick up prescription. In Drafts, the action is called Send to Due. So on the command line, I type the following:

export message="6pm pick up prescription"

export action="Send to Due"


(In my case, I type ~/j/scripts/pushover. If Terminal says you don't have permission to run the script, type chmod 700 pushover.)

Your notification will be sent to Pushover, and you'll get a status response on the command line. When you get your notification, just swipe to open it, and tap on the URL string. In the example above, it would look like


When you tap on the URL, it will send the text to Drafts and tell Drafts to send that text to Due.

If you just want to send text to Drafts and not immediately act on it, just leave the action variable null. To clear the action variable from a previous notification, type unset action.

There are additional variables you can add to the script (as defined in Pushover's API) if you want to send your notification to a specific device or customize the sound. Just add an additional line in the script, like -F "sound=cashregister" \.

Last built: Thu, Oct 16, 2014 at 2:47 PM

By Jeffrey Kishner, Friday, May 23, 2014 at 8:47 AM.