Posts tagged: applescript

Launchbar to Twitter (to Toodledo)

By , November 7, 2011 9:11 am

I’m a big fan of LaunchBar–the best quick launcher for Mac I have yet found–and have become a heavy user of Toodledo for task management–which I also recommend. So it was natural that I would want a way to add tasks to Toodledo quickly using Launch Bar. The easiest intermediary seemed to be Twitter–you can add tasks to Toodledo using a direct message–so after much searching and stealing of code (I’ve never used AppleScript before), I cobbled together the following system using AppleScript and the Twurl command-line Twitter client. This could be modified relatively easily to be a quick way of just posting to Twitter generally.

Step A

If you haven’t already, you obviously need to:

  1. Install LaunchBar
  2. Join Twitter
  3. Join Toodledo

Step B

Install Growl, which I use to notify the user that the addition was successful. You can hack those lines out of the code if you want.

Step C

Install the Twurl package (which is a Ruby “gem”). This is easily done via the command line. Fire up your terminal and use the following command to install Twurl:

sudo gem install twurl

Then add your Twitter keys so Twurl can post to Twitter using your identity:

twurl authorize --consumer-key YOUR CONSUMER KEY  --consumer-secret YOUR SECRET KEY

(You get these keys from the Twitter Dev site. If you don’t have anything there yet, sign in and use the create an application link. Choose a name you can remember, such as ASTwitter, and use your web site as the “callback” address)

Step D

Open up the AppleScript Editor and create a new script with a name that matches the command you want to use in LaunchBar. I call mine td.scpt. Paste in the following code, and save the script to to the ~/Library/Application Support/Launchbar/Actions folder:

on handle_string(inTweet)
    tell application "System Events"
        set isRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
    end tell
    if isRunning then
        set qTweet to quoted form of ("screen_name=toodledo&text=" & inTweet)
        set twitterPost to "twurl -d " & qTweet & " /1/direct_messages/new.json"
        set twitterResponse to do shell script twitterPost
        my growlRegister()
        if twitterResponse contains "<error>" then
            growlNotify("Error Adding ToodleDo Task", "Post Failed. Twitter Down?")
        else
            growlNotify("ToodleDo Task Added", inTweet)
        end if
    end if
end handle_string

using terms from application "Growl"
    on growlRegister()
        tell application "Growl"
            register as application "Toodledo Add" all notifications {"Alert"} default notifications {"Alert"} icon of application "Growl.app"
        end tell
    end growlRegister

    on growlNotify(grrTitle, grrDescription)
        tell application "Growl"
            notify with name "Alert" title grrTitle description grrDescription application name "Toodledo Add"
        end tell
    end growlNotify
end using terms from

Step E

Use your new action! Invoke LaunchBar and type the name of the script (aka the shortcut):

Launch script using LaunchBar

Press enter and add the title and other info for your task:

Entering a task

Press enter again and when the Tweet has been posted, you will receive a confirmation from Growl:

Growl notification

Notes

  • Your mileage may vary. Use at your own risk. No lifeguard on duty.
  • I’ll try to help if you ask in the comments, but I have limited time and expertise to do so!
  • The script doesn’t actually check that the task was added to Toodledo, only that the Tweet was sent. There can be a lag between the Tweet and your new task’s appearance on Toodledo.
  • This code is cobbled together from various sources and help files… thanks to all those folks.

Panorama Theme by Themocracy

Creative Commons Attribution 3.0 Unported
This work by Chris Lott is licensed under a Creative Commons Attribution 3.0 Unported.