Control your Mac from iOS using Dropbox and Applescript
[day after posting UPDATE: this is just a start. I’m going to start working on a more intuitive way (than having to peck out all kinds of applescript in long hand on an iOS keyboard) to do this, and if anyone else is interested in working on it (probably a folder action script that can read some natural language commands) please email elasticthreads at gmail or twitter @elasticthreads]
So in the past few weeks a bunch of text editing apps for iOS have been released that use Dropbox to sync with your desktop computer. Here’s a good roundup of them. I’ve been really liking Plaintext, and was wondering what I could use it for besides just plain writing text…
And then I remembered Folder Actions, which are an OS X feature that lets you set an applescript to run whenever a file is added to a folder (or deleted). And since you can run one applescript file from another, I realized you could write an applescript in Plaintext and have your Mac run it. Which opens a pretty large window for controlling your Mac (as long as its running, and has Dropbox installed, and has a single Folder Action set up) from anywhere in the world just by writing some applescript in Plaintext. This should work with any Dropbox based text editor (Elements, Writer, Nebulous Notes, etc.), and might even work with Simplenote and Notational Velocity, but I’ve only tested this with Plaintext.
So that last night when I left my apartment with my stereo blasting from my Macbook Pro’s iTunes, to turn it off from miles away all I had to do was type this into a new file in Plaintext: tell application “iTunes” to quit
I came home late that night to a quiet apartment and no angry neighbors.
Here’s how to do it in case you’re interested:
First set up your Mac:
1. Download the Folder Action script here. Move that script to the following folder:
~/Library/Scripts/Folder Action Scripts/ (where “~” means your home folder). If you don’t have a “Scripts” folder in your library, or don’t have a “Folder Action Scripts” folder in the “Scripts” folder, or both, create them.
2. Go to the folder in your Dropbox where you sync your notes from Plaintext (or whatever app you use). The default for Plaintext is ~/Dropbox/Plaintext. Create a new folder inside of that folder and name it something useful like “dbScripts”.
3. Right-click on your new folder and look for a command in the contextual menu named “Folder Actions Setup…” and select it.

4. A list of available folder action scripts should pop up. Select the script we set up in step 1.

5. You should see a window with the name of your folder next to a checked checkbox, the name of your script next to a checked checkbox and “Enable Folder Actions” next to a checked checkbox.

We’re now done setting up your mac. Anytime you put a text file in that folder, your Mac will try and run it as an applescript.
Now a couple things to set up and consider in Plaintext:
1. So fire up Plaintext (or whatever app) on your iOS device and, after it loads up the contents of your notes folder, scroll around and find the folder we just created in Dropbox on your Mac. Select that folder.

2. Anytime you create a new file in that folder, or change the name of an existing file in that folder, after Dropbox works its magic, your Mac will try to run it as an applescript.
But first: there’s a key setting you need to check in Plaintext before testing this out. Hit that little cog in the lower left corner of Plaintext to bring up Settings. Select Dropbox settings:
Make sure that “Sync on Edit” is off.
if Plaintext syncs while your editing, then when you go to create a new file and then start typing your applescript, Plaintext will sync it over to your Mac when it just is an empty file and the folder action will run an empty script. Since Folder Actions only get run when a file is added (not changed), by the time you’re done with your script it will be too late. So turn this setting off.
So now, in Plaintext, you’ll navigate to your scripts folder, create a new file, name it, write the script, and then hit the back arrow to close that file, AND THEN Plaintext will sync it over to your Mac where it will get run.
An easier way to run a script if you have an existing file in your folder with a script that you want to run, or one that is close to what you want to run (for example, if you want to tell application “Safari” to quit instead of “iTunes” to hide that embarrassing page of NSFW), just open that existing file and, change whatever part of the script you might want to change and ALSO change its name. Changing the name of a file in Plaintext will cause Dropbox to delete the old named file and create a new file with the new name (which will then trigger the folder action).
Good scripting!