★ Importing Mavericks Tags to Evernote

I have a Hazel-based workflow defined for scanned documents. With the release of Mavericks, I added tagging to that flow for things like the company that generated the document, a few tags about what the doc is about (cars, kids, etc). However, I like keeping the docs in Evernote. So, as I usually do, I turned to Applescript and came up with this:

set theActualFile to choose file

set theFile to quoted form of (POSIX path of (theActualFile))

set origDelim to AppleScript’stext item delimiters

set newDelim to “,”

set AppleScript’stext item delimiters to newDelim

— Get tags from file

set userTags to (do shell script “mdls -raw -name kMDItemUserTags ” & theFile)

set theTags to (every text item of userTags)

tell application “Evernote”

set theNote to create note from file theActualFile

–Clean up the list, removing whitespace, quotes, parenthesis, tabs, newlines

repeat with theTag in theTags

— sed command in line below taken from stib’s answer on this page: http://stackoverflow.com/questions/2783713/applescript-cleaning-a-string

set theTag to do shell script “echo ” & quoted form of theTag & “| tr -d ‘\n'”

set theTag to do shell script “echo ” & quoted form of theTag & “| tr -d ‘\r'”

set theTag to do shell script “echo ” & quoted form of theTag & “| tr -d ‘[:blank:]'”

set theTag to do shell script “echo ” & quoted form of theTag & “|sed \”s/[^[:alnum:][:space:]]//g\””

— TODO need to clean out newline as well

if not (tag named theTag exists) then

set my_new_tag to (make new tag with properties {name:theTag})

assign my_new_tag to theNote


assign tag theTag to theNote

end if

end repeat

end tell

set AppleScript’s text item delimiters to origDelim


The workflow asks for a file to be chosen (I’ll fix that so it accepts a file argument later when I’m ready to make it a part of the automated flow), gets the tags as string (via mdls), splits it out, and then strips out the newlines, tabs and whitespace from each of the tags.

Two caveats.

1) I assume it will split apart any tag with a comma in it.
2) It will remove whitespace form inside the tag as well – so a tag of “credit card” will become “creditcard”… but I’m okay with that.

Here’s the Applescript for your downloading pleasure: Import File to Evernote.scpt

★ Banking

I’ve struggled with finding a good way to know my bank account balance on the go. Logging in to the bank’s app or website shows me what they know about, but future transactions don’t show up there, even if they’re in their own Bill Pay function. Mint has the same problem, but also gets flaky on pending transactions. I had been using Quicken Essentials for balancing, but Intuit has apparently decided there’s no need for an iOS version. 

So I’ve built my own structure. I wrote a script for Fake.app to log into my bank’s website, download the last few days of transactions and log out. I run this script every day. Hazel picks up the downloaded file and imports it into Moneywell, and then marks it as ok for deletion.

Moneywell has a number of interesting features, most of which I don’t use. What brought me to them was that their iPhone app syncs via Dropbox and is free for a single account… which is all I need to monitor. I had picked up a license for their Mac application a few years ago, so I upgraded to the current version and *poof* I now have up to date information on my current account balance and what upcoming expenses I have. 

★ The new Grocery List process

So now that I’m not using my Applescript and Numbers grocery list, how am I doing it? 

Two key pieces – Drafts for content entry and Evernote for storage. I created a notebook in Evernote specifically for lists.

In Drafts I have tow actions defined. One adds the current note to a predefined groceries note in Evernote. But there’s lots of time where I need to add items to a non-grocery list, like Target,  home improvement or pet stuff. So I have a separate action which reads the first line of the note as the notebook and adds the rest of the note to that list.

Because I’m a packrat, I also keep the old lists around. Once I’m done at the store, I rename that list by appending the date to it. (And if Evernote would support TextExpander, that’d be even easier — hint hint). 

★ Catching up.

Guess I should follow up with where I am with the projects from previous posts.

Grocery lists (here and here): I’ve stopped adding them to the Numbers spreadsheet. Took too long and had some fragility issues around the script that processed the data on the Mac. Instead, I use Drafts to post things to the list in Evernote.

Date recognition (here): Became a moot point when Hazel added a better implementation to its rules.

As for task management, I’m using a variation on The Secret Weapon which probably needs some more revision. (Future post, I’m sure.) At the time, I liked the idea of using Evernote and was headed towards it being Where I Lived. I still use it a lot, but I don’t live there. More of a vacation home, really.

★ Adding Items to the Grocery List

So last week I mentioned my shopping list spreadsheet.

However, there’s one flaw. My Mac isn’t in the kitchen, and adding things to the spreadsheet via Numbers on my phone is… awkward at best.

But I can send a text with my phone. And I have Messages running on my Mac. And I read this. And it all clicked.

So now I text “gr milk” and milk gets added to my grocery list, it gets sorted by aisle and saved to iCloud. And it only works if I do it from my phone. Don’t need anyone adding things to my list.

While I was at it, I added commands to quit Chrome and to fire up iTunes.

There’s one more thing I want to do to this – I want to make a small script that calls this one, instead of having Messages call it directly. the reason is that when you edit the script, you need to re-add it to Messages and honestly, it was becoming a bit of a pain during debugging.

Here’s my script:

on nextEmptyCellInColumn(sheetName, tableName, colNumber, compValue)
— Copied from http://applescript.bratis-lover.net/library/iwork-numbers/#nextEmptyCellInColumn
— Finds next empty row in the spreadsheet
local sheetName, tableName, colNumber, res, i, len
tell application “Numbers”
tell document “Groceries”
tell sheet sheetName
tell table tableName
set len to row count
set res to 0
repeat with i from 1 to len
if (value of cell colNumber of row i) = compValue then
set res to i
exit repeat
end if
end repeat
if res = 0 then
error “No empty row in table ” & tableName & “!” number 111
end if
end tell
end tell
end tell
end tell
return res
on error eMsg number eNum
error “Can’t nextEmptyCellInColumn: ” & eMsg number eNum
end try
end nextEmptyCellInColumn

using terms from application “Messages”
on message receivedtheMessagefromtheBuddyfortheChat
set theName to full name of theBuddy
if theName contains “Neil Kelly” then
if theMessage starts with “COMMANDS:” then
— This is here to prevent the reply for commands from triggering all the commands
set a to 1
if theMessage contains “itunes” then
tell application “iTunes”
end tell
end if
if theMessage contains “chrome” then
tell application “Google Chrome”
end tell
end if

if theMessage starts with “gr ” then
set numCell to nextEmptyCellInColumn(1, 1, 1, 0)
set groceryItem to text 4 thru (length of theMessage) of theMessage
tell application “Numbers”
tell document “Groceries”
tell sheet 1
tell table 1
set value of cell 1 of row numCell to groceryItem
sortbycolumn 2 directionascending

end tell
end tell
end tell

end tell
end if
if theMessage contains “commands” or theMessage contains “help” then
— reply with list of commands
— this doesn’t autogenerate
— so if you add a command you should document it here too
— backslash-n adds a newline
gr to add to grocery list
chrome to quit chrome
itunes to start itunes” to theChat

end if
end if

end if

end message received

end using terms from

★ Grocery Lists & Data Collection

I tend to be the one who does most of the grocery shopping for our family. I’ve always been curious about some of the data that could be collected – specifically, pricing data and how often we purchase certain items. So I built a spreadsheet. (You know how they say “To a child with a hammer, everything is a nail”? Yeah, well, spreadsheets are my hammer.)

Of course, just a list of all the stuff we buy with prices paid would be annoying to keep up – since there’s a lot of stuff we don’t buy every week, there would be a mountain of empty space to deal with. Okay, so two spreadsheets – one with a list of everything, and another with the current week’s list. And since my preferred store offers a list of items and aisles, I can start with that. Fire up the scanner, fix some minor OCR issues and I have a list of lots of what they sell and where in the store it is. This is important because…

I like my grocery list to be in the order I’m going through the store. So do a VLOOKUP on the item name and get the aisle number. Works for lots of stuff, manually add a few items to the store directory and away we go.

I used a Numbers spreadsheet for this task – sure, Excel has lots of geekery going for it, but Numbers has iCloud which means I can edit on my desktop with amenities like mouse and keyboard, and update at the store on my phone.

Next up… geeking out on adding items to the list.

★ Off The Secret Weapon, Back to Remember The Milk

That was fast. 

Unfortunately, I pretty quickly remembered what I didn’t like about The Secret Weapon. Because it’s within Evernote, it was always multiple steps to add a task, multiple steps to see what’s on my list, and multiple steps to make sure I was only looking at my 1-Now list instead of everything. And I never felt confident that I was getting everything into view. 

I did scan all the business cards I’ve gotten and held on to into Evernote though. So now I can take a bunch of folks out of my contacts list – people I’ve met, good to have handy but don’t need to be clogging up the Address Book.

I’m finally starting to get Evernote. Kind of. For me, it’s to notes what Dropbox is to files – always around, synced on all my devices. I think with a bit of tinkering I can get it into my workflow. 

Next up, some good old fashioned automation. 

★ Starting with The Secret Weapon and Evernote

I decided it was time to go all-in with Evernote. I’ve been toying around with it here and there and trying to figure out how it would fit into my workflow. I had been using Remember The Milk, and while it worked, it never felt quite right. I had read about The Secret Weapon, a GTD process built on Evernote, and tried it once before, but had dropped it because of two perceiving missing items. One was location based reminders, which I could get with RTM’s app, and the other was an easy way to handle recurring tasks without cluttering up my to do list. 

As it so often turns out, I didn’t actually need the location based reminders. So how could I get recurring tasks? Hm. IFTTT could write to Evernote. So now I just needed to figure out how to trigger IFTTT at the right time. If it was just one or two tasks at predictable times, I could probably use the Date & Time trigger. But I want something flexible so I don’t need to create recipes for each task. FInally, it dawned on me. Create entries in Google Calendar, put “[todo]” in the event description, and create an IFTTT trigger for events matching a search to write into my Evernote notebook. 

I guess we’ll know if it works on Friday when I need to clean the litter box. 

★ Using Automator to Get At Things Applescript Won’t Cooperate With

One of the things that drew me to the Mac was Applescript – the idea of a scripting language that would work with most of the programs in the OS was… well, pretty freaking cool.

However, “most of the programs” eventually means “not the program I was using.” Then I came across this article – by using the Automator “Watch Me Do” recording function and a little bit of trickery, you can get the Applescript code to do whatever you need.

Random Useful Mac OS X User Tips: “I lamented this in one of my posts about Leopard, but I noted that there didn’t seem to be a way to directly access the AppleScript code from the Watch Me Do feature — Automator only creates run-only plugins or scripts. This is annoying if you want to modify the UI script later to do something slightly different. In this situation, you’d have to redo the whole set of actions all over again.”

Way cool.