Homemade Continuity with Drafts and AppleScript

I’ve started using Drafts on iOS for building and automating posts for this blog, and I discovered it’s a great tool also for quick notes.

But, sometimes, I need to pick up this note and continue to edit on my Mac (a sort of homemade Continuity). Yes, you can use some Drafts actions for saving it on Dropbox and then you can open your file from your Mac but, the meaning of automation is minimising your effort in order to complete a task.

So, I’ve started to thinking about how to automate this. This is the result flow I want: - Start writing down something on Drafts - Tell to Drafts that I want to stop to editing here and continue on my Mac - Start editing on Mac

No more, no less. Obviously, I found a solution. This is what you need: - A Dropbox account - Drafts on iOS, with Dropbox link enabled - The Dropbox client installed on your Mac - A text editor on Mac. I use MacVim

##Prepare Dropbox environment I want to keep things separated in Dropbox, so I create a new directory named /Drafts/AutoOpen. All markdown files (with .md extension) saved in this directory will be automatically opened.

##Configuring Drafts On Drafts I’ve made a new action called “Edit on MacBook”. It’s a 1 step action which creates a file in Dropbox. Here the action configuration:


This will create a new file containing your draft in the /Drafts/AutoOpen Dropbox directory. The file will have the .md extension and replaces files named in the same way. Before saving the new Action in Drafts, ensure to select Delete as “After Success” parameter in the action. This will delete the draft after the upload on Dropbox, avoiding concurrent updates on the Mac and on the device.

##Configuring Mac Now we need to tell OS X to open MacVim when a file is added to that directory. We can do this with an AppleScript and the integrated Folder Actions. First of all, launch “Script Editor” on Mac and save a new script named “add - open with MacVim” in the directory ~/Library/Scripts/Folder Action Scripts. If this directory doesn’t exists, simply create it. Then insert this code in the script:

on adding folder items to this_folder after receiving added_items
        set MDExtension to {"md"}
        tell application "Finder"
            repeat with draft in added_items
                if name extension of draft is in MDExtension then
                    open draft with MacVim
                end if
            end repeat
        end tell
    end try
end adding folder items to

The code is really simple: for each file added to the directory, if the extension is .md, tell to Finder to open that file with MacVim.

Now we can bind this script to our directory. Navigate in ~/Dropbox/Drafts folder, Ctrl+Click on AutoOpen directory, and select Services->Folder Actions Setup…

Folder Action 1

Enable Folder Actions, then select add - open with MacVim.scpt script. This bind your script to the directory.

Folder Action 2

Now everything should work as expected and you can continue writing your draft from iOS to OS X.

##Other things to do

Sometimes you want to pick up a file on your Dropbox and edit it with Drafts. And you want to do this without having the Dropbox iOS app installed or browsing the Dropbox site. I’ve set up an Action in Launch Center Pro in order to quickly do this operation.

I’ve already have an action, named Draft Clipboard for quickly add clipboard content to a new Drafts:


And, in my case, this action ID is 187 (you can edit your action and scroll to bottom in order to view its ID). So, I’ve built a new action in LCP named Edit Drafts, with this URL:


This will present to you a screen for choose a file in the /Drafts directory on Dropbox, copy the content of that file into clipboard, then open Drafts and create a new drafts with the content of the clipboard.

Really quick.

Written on December 4, 2014 - #iOS #Automation #AppleScript