Import Moves for iOS Logs to Day One

I’ve been using Moves for iOS to track my movement and I wanted to add the saved images the app can produce to Day One for OS X for journaling purposes.[1] So, if you create a Hazel rule to check if you have one of these images, you can then process them with this AppleScript. This script assumes you created the log the following day (or the moves) and then it uses that created day –1 to create a Day One entry for the day the moves actually happened.

set theFile to choose file

tell application "System Events"
    set old_date to creation date of (info for theFile)
    set new_date to old_date - days * 1
    set processed_date to ((month of new_date as number) & "/" & day of new_date & "/" & year of new_date as text) & " 11:59PM"
end tell


set photo_path to quoted form of POSIX path of theFile

set the_script to "echo \"Moves\"" & "| /usr/local/bin/dayone -d=\"" & processed_date & "\" -p=" & photo_path & " new"

do shell script the_script

When you’re running this as an embedded script in Hazel, just remove the line where you set theFile. Also, you’ll have to manually export the file from Moves. There’s no way to automate that unfortunately.


  1. You will need the Day One CLI.  ↩

Use Hazel and Dropbox to Add Photos to Day One

I got to thinking that it would be nice to automate adding images to Day One. Using the Day One CLI, I whipped up a quick Hazel rule that will do that.

Hazel

Hazeldayonecode

Here’s the code:

echo "" | /usr/local/bin/dayone -p="$1" new

It works and will add your images without having to open up Day One. The only caveat is that you’ll have to add text and tags later.

Automating Koku Transactions on iOS

What I’m about to describe is a way to automate transaction creation for the finance app Koku. I’m aware there’s an iPhone app, but it lacks a URL scheme and a way to automate making new transactions. This is my (successful) attempt to make automation with Koku possible.

On OS X

You need three pieces of software on OS X to use this system: Koku (of course!), Dropbox and Hazel. You could do this with folder actions, but Hazel is better and easier to use.

Hazel koku

Hazel

Hazel needs to monitor a folder where you’re going to upload .plist files containing the information about the new transactions you’re creating. It just needs to be somewhere in your Dropbox folder. Set your Hazel rule to match files where all are true:

  • Name starts with Koku transaction
  • Extension is “.plist”

That’s it.

The action you’ll run is “Execute AppleScript” and here is the AppleScript you’ll paste it:

--Get the file name as text so that you can use it with "property list file".
set theFile to theFile as text

--Get values from the property list file you'll create with Drafts on iOS.
tell application "System Events"
    tell property list file theFile
        tell contents
            set _desc to value of property list item "name"
            set _cost to value of property list item "cost"
        end tell
    end tell
end tell

--Create the transaction.
tell application "Koku"
    activate
    tell document 1
        --Change the account name to the account you want to add to in Koku.
        set theTransaction to mktrans in account "Cash"
        set date of theTransaction to (current date)
        set description of theTransaction to _desc as string
        set withdrawal of theTransaction to _cost as number
        set seen of theTransaction to true
        --This is where you can add custom tags for transactions.
        --Add as many as needed.
        if _desc is "Food" then
            addtag named "food" to theTransaction
        end if
    end tell
end tell

What this will do is pull a transaction name and cost from a .plist file and create a new transaction in your “Cash” account and then insert the supplied data. Because of the limited amount of information that Drafts can parse, you’re limited to two data points. Setting up:

if _desc is "Food" then
    addtag named "food" to theTransaction
end if

…will allow you to add tags, but only if you tell the script what titles to look for.

On iOS

On iOS you need Drafts and Launch Center Pro to make this all work well.

Drafts

In Drafts, create a Dropbox action called “Koku”. This will be a template that will upload a .plist file with [[title]] placing the first line of the draft into the .plist as the transaction title and [[body]] inserting the amount. With just this template, you can create a number of Launch Center Pro actions that will insert the necessary text where it needs to be. Here is the .plist template:

Open this link on your iOS device to import .plist template into Drafts

2013 02 27 12 43 21

Launch Center Pro

Launch Center Pro will be responsible for supplying Drafts with the data that Drafts needs to create the .plist files. You’re essentially supply Drafts with:

[name]
[cost]

What you’ll need to do is send:

[name]%0A[cost]

The name being the transaction title, “%0A” is a url encoded line break and cost is the amount of the withdrawal.

Here’s an example for a “Food” transaction action URL:

drafts://x-callback-url/create?text=Food%0A[prompt-num]&action=Koku

You can change any titles or insert a specific cost in to make it even more automatic, like this one for my train pass that costs ¥1000.

drafts://x-callback-url/create?text=Train%0A1000&action=Koku

The last example I’ll show you is one to add variable titles and costs. Launch Center Pro will not let you use a keyboard prompt and a number prompt in the same action so you need two actions. One will give you a prompt, send the text to Drafts, Drafts will run its “Set draft to clipboard” action and then drop you back in Launch Center Pro. Then, run the second “Set Cost” action and that will send the clipboard as title and inputted cost as cost to your regular “Koku” action and then upload a plist as normal.

--Copy to Clipboard
drafts://x-callback-url/create?text=[prompt]&action=Copy%20to%20Clipboard&x-success=launchpro://

--Set Cost
drafts://x-callback-url/create?text=[clipboard]%0A[prompt-num]&action=Koku&x-success=launchpro://

There you have it. A working system to automate Koku transaction creation from iOS. Is it worth it? There is a Koku iPhone app after all. But if you enter the same transactions over and over, you’ll get tired of using the Koku iPhone app all the time. With a little bit of set up, this system works pretty well.

Starting Magnet Links Remotely

Updated 2013-03-01: I realized that if Transmission wasn’t already open, the GUI scripting would get passed over, so I added a bit to see if Transmission is the frontmost app.


I’ve been using Keyboard Maestro for months now to take a text file with a “magnet:” link inside, read the text out of it, and then simulate the keystrokes necessary to open the link in Transmission. I saw something similar done with just AppleScript and System Events’ GUI scripting capabilities so I got motivated to do my own system purely in AppleScript.

Here’s the AppleScript:

open for access theFile with write permission
set fileContents to read theFile using delimiter {linefeed}
set theString to fileContents
set the clipboard to theString as text
close access theFile

tell application "Transmission"
    repeat until frontmost is true
        activate
    end repeat
end tell

tell application "System Events"
    tell process "Transmission"
        keystroke "u" using {command down}
        keystroke "v" using {command down}
        delay 1
        keystroke return
    end tell

end tell

tell application "Finder"
    delete theFile
end tell

I have Hazel watch my notes directory in Dropbox for a file named “torrent.md” and when it sees that file, it reads the contents, sets the clipboard to those contents and then opens an “Open link…” menu item, pastes the text and hits “enter”. This fires the torrent up in Transmission and then deletes the original file. I recommend deleting the text file each time instead of setting the eof to 0 because I feel like Hazel more reliably catches the totally new file better than just a changed file.

I have another Keyboard Maestro macro on my remote Macs that create the text file from the copied link and also on my iPhone, I have Drafts Dropbox actions tied to Launch Center Pro actions that can create the file from the clipboard on the iPhone as well. The trouble I go to just to be able to get the latest Linux distros!

Hazel is how I keep my desk(top) clean.

Screen shot 2011 02 22 at 2 21 10 PM

Let me count the ways

Hazel is one of those apps that you never even knew you wanted, let alone would love, until someone else tells you about it. I first heard about Hazel a few years ago from an episode of MacBreak Weekly with Merlin Mann. I downloaded it, didn’t get its value at first glance, and then promptly dismissed it and trashed it. I wonder, now, at how much more productive and organized I could’ve been if I had been using Hazel these past three years. Hazel is one of the most useful applications you’ll ever use and here’s why.

Delete apps completely

When you trash an application, there’s always a trail of support files lingering around on your hard drive afterwards. With Hazel running, all those support files and plists get trashed along with the application. AppTrap is a free utility that does the same thing but Hazel tends to be faster at finding those files, however. And Hazel gives you a lot of control over your trash can. You can have Hazel auto-empty the trash after a user-determined period of time or when the trash has a certain amount of data in it. You can even have it auto delete files that exceed the trash can’s new limit. Did I mention it can securely empty the trash too?

Screen shot 2011 02 22 at 2 13 57 PM

Meat and Potatoes

The real reason to use Hazel though is what it does with folders. This is also why you might not get how awesome Hazel is either. Hazel will monitor folders, be it your Downloads, Desktop or anything else. You can set up a list of rules (any or all) and then an action to do done to files that meet those criteria. It sounds arcane for sure, so I’ll give you an example that I actually picked up from Mac Power Users.

Let’s say you use Omnifocus. Omnifocus likes to create a backup or two of its database everyday. After a few months of use, these backups, if you’re managing a lot of projects and tasks, will start taking up a lot of space. This can be a waste, especially if you’re using an Air with limited drive capacity. So with Hazel, you can monitor the folder where all those backups get stored and set up a rule that says to take all the backups that were created more than a month or two weeks or however long ago and trash them. Or copy them to Dropbox. Whatever. So everyday, Hazel gets rid of these old Omnifocus backups for me and keeps my hard disk from filling up with files I’m never gonna use again.

Screen shot 2011 02 22 at 2 13 28 PM

Want another good example? I download a bunch of crap. Any file in my ‘Downloads’ folder that hasn’t been opened in 24 hours get a red label attached to it so it stands out and maybe I’ll act on it. Or how about all those files that pile up on my desktop? I’ve got a rule that takes any file on the desktop that hasn’t been modified in 48 hours and moves it to a folder on the desktop called ‘Inbox’. Some call that folder ‘Review’, it doesn’t really matter what you call it, but it clears the clutter off the desktop and then when you do your daily or weekly GTD review, you’ve got all the things you need to check on in one folder. It’s kept my desktop and head clear.

No complaints here

I’m usually a bitchy guy when it comes to software, but Hazel has left me complaint-free for once. I’ve had a couple “folder monitor” crashes on my MacBook Pro but my MacBook Air (which has a fresh OS install unlike the Pro) has had no issues at all. There’s a 14-day free trial and it’s $21.95 for a license. Buy it here.