This is my old blog. My current writing is here:

Wesabe API vs. Quicksilver

As you may have noticed, we at Wesabe just released an API allowing you to access your financial data on your own terms.

So what do I do with APIs? I write little Quicksilver Applescripts for them. So here’s how you get a listing of your bank accounts with their current balances via Wesabe through Quicksilver.

The Script

(* Wesabe API Thingy for Quicksilver
 * (c) 2007 Coda Hale <>
 * MIT License

--- pull out the username and password for a website
on getCredentials(serverName)
    tell application "Keychain Scripting"
        set ourKey to first Internet key of current keychain whose server is serverName
        set ourCredentials to (account of ourKey & ":" & password of ourKey)
        return ourCredentials
    end tell
end getCredentials

--- shell out to curl to download the accounts listing in XML
on downloadAccounts(credentials)
    set curlCommand to "/usr/bin/curl --silent --show-error --user " & quoted form of credentials & ""
    set results to do shell script curlCommand
    return results
end downloadAccounts

--- use System Events to parse the XML and return a list of account names and balances
on getAccountBalances(xmlData)
    tell application "System Events"
        set accountBalances to ""
        set xmlDocument to make new XML data with data xmlData
        set accountElements to XML elements of XML element "accounts" of xmlDocument whose name is "account"
        repeat with accountElement in accountElements
            set accountName to value of (XML element "name" of accountElement)

            if (XML elements of accountElement whose name is "current-balance") ≠ {} then
                set accountBalance to value of XML element "current-balance" of accountElement
                set accountBalance to "(none)"
            end if

            set accountBalances to accountBalances & accountName & ":  " & accountBalance & "
        end repeat
        return accountBalances
    end tell
end getAccountBalances

--- actually execute this stuff
set xmlData to downloadAccounts(getCredentials(""))
set balanceText to "Your Wesabe Accounts:
" & getAccountBalances(xmlData)

--- and put it on the big screen
tell application "Quicksilver"
    show large type balanceText
end tell


Toss the above into Script Editor, and save it as an Application someplace where Quicksilver will pick it up (I called mine “Wesabe Accounts”). You should have an entry in your Keychain for — that’s where the script reads your username/password.

Using The Damn Thing

Run it from Quicksilver. It’ll look like this:

Wesabe via Quicksilver

If you want it to do something different, go for it. Add some functionality, put it up on your blog, and add a comment here with a link there.

I’m really interested to see what kind of stuff people make with this.

5 Responses to “Wesabe API vs. Quicksilver”

  1. Tim Case Says:

    fucking awesome.

    I wasn’t sure if I was going to use wesabe but the api today just changed everything.

    This little script is exactly what I wished for.

  2. Chris Says:

    It runs pretty slow on my machine — there is a long wait before the Keychain pops up to ask permission. In fact, it takes less time to actually go to and check my accounts manually. I must have done something wrong.

  3. Adam Keys Says:

    Your apparent fearlessness in the face of AppleScript’s eccentricities inspires me.

  4. Matthew Hall Says:

    I found that scripting the keychain can be a real dog - so I discovered a workaround when I hacked a Twitter posting script for QuickSilver : take a peek at an alternative way to script the keychain using a little command line-fu … avoid keychain scripting

  5. Jack Turner Says:

    This script is wonderful. Now I finally have a reason to use my wesabe account.

    Only problem is that the Application stays open and needs to be manually quit if i choose “stay open” as an option when I build it. And if I don’t choose stay open it quits immediately and the large QuickSilver text disappears with it.