Quicksilver Adium Message Script

The Adium plug-in for Quicksilver has been kaput for quite a while now, and I have found myself as of late with folks at work I need to contact who keep themselves in the invisible state in their messenger (like my manager ;-). I have come to loath having to go to Adium and go to the menu bar with the mouse and select “show offline contacts” and then find the person I want to IM and click their name, then “hide offline contacts” again. I also don’t care about having to use the contact list interface anyway, really, if I didn’t have to, so I wrote this applescript to use in Quicksilver.

To install, uncompress this script and put it in your ~/Library/Application Support/Quicksilver/Actions directory, and restart Quicksilver.

To use, invoke Quicksilver and type “.” to enter text mode. Type all or part of the name of the person you wish to IM. Hit and type “Adium” (or “Ad” or “Adi”) and select “AdiumContactor” with the arrow keys and hit .

The script will search for any instance of the text you enter in your contacts, both in their IM names, as well as their display names. If one match is found, it will open an IM window for that contact. If multiple contacts are found, a window will open allowing you to select the one you want, using whatever account it belongs to. (in other words, if you search “bil”, you will be able to choose from “Bill Todd”, bileInMyStomach@gmail.com, actionscriptAbility@hotmail.com, etc.) Careful using some search terms, such as “com”, as it will return all your MSN messenger accounts (whose screennames are defined by the contact’s email address)

PlasticWare Downloadable ::
AdiumContactor for Quicksilver (Aug. 07, 2008)
Download (~10,000 bytes) :: AdiumContactor.zip

quicksilver, curl, applescript, proxy-config, twitter

This explains how to use Quicksilver to send posts to Twitter from within a firewall. I made this my little lunch project today. First, let's start with the basics. If you set up your work proxy server in your network config, there is not really any way to easily retrieve those settings. Let's say you are using http://proxy.myco.com:3128 for your http proxy settings. In the Terminal, you have not actually set your http_proxy environment variable. Mark Assad has proxy-config available for download. You can grab that, put it in one of your path directories, and then in your .bashrc or .zshrc file the following:

export http_proxy=`proxy-config -h`
export https_proxy=`proxy-config -s`
export ftp_proxy=`proxy-config -f`

This will set your environment proxy variables to whatever they are currently set to in your Network Preferences. I got part of this also from Ryan Tomayko's blog.This is important if you are inside a firewall at work.

The simplest way to post a tweet to twitter from the command line would be to do so using cURL. If you don't have cURL installed, you will need to install it. If you aren't familiar with cURL, it is basically a command-line tool for grabbing html documents (or whatever else). See this post for another use. I got this idea, as well as the applescript for using it with Quicksilver, from Coda Hale's blog. Read that post for a full explanation of using Quicksilver and an applescript for posting to twitter from Quicksilver -- it has a pretty thorough explanation.

If you are inside a firewall, however, this will likely fail because the cURL command requires that the proxy settings be provided. So, I took the script from Coda's post, combined it with the comment on his post from Daan Kortenbach, and then enabled that for use with the system's proxy settings. The new script follows:

CODE:
  1. using terms from application "GrowlHelperApp"
  2.     -- Register Growl
  3.     on growlRegister()
  4.         tell application "GrowlHelperApp"
  5.             register as application "Tweet" all notifications {"Alert"} default notifications {"Alert"} icon of application "Quicksilver.app"
  6.         end tell
  7.     end growlRegister
  8.    
  9.     -- Notify using Growl
  10.     -- Example: growlNotify("This is an Alert","This is a test of the Growl Alert System")
  11.     on growlNotify(grrTitle, grrDescription)
  12.         tell application "GrowlHelperApp"
  13.             notify with name "Alert" title grrTitle description grrDescription application name "Tweet"
  14.         end tell
  15.     end growlNotify
  16. end using terms from
  17.  
  18. using terms from application "Quicksilver"
  19.     on process text tweet
  20.         tell application "Keychain Scripting"
  21.             set twitter_key to first Internet key of current keychain whose server is "twitter.com"
  22.             set twitter_login to quoted form of (account of twitter_key & ":" & password of twitter_key)
  23.         end tell
  24.         set twitter_status to quoted form of ("status=" & tweet)
  25.        
  26.                 -- I have proxy-config in a directory "~/bin"
  27.         set the_proxy to do shell script "~/bin/proxy-config -h"
  28.        
  29.         try
  30.             if (the_proxy = "") then
  31.                 set results to do shell script "curl --user " & twitter_login & " --data-binary " & twitter_status & " http://twitter.com/statuses/update.json"
  32.             else
  33.                 set results to do shell script "curl --proxy " & the_proxy & " --user " & twitter_login & " --data-binary " & twitter_status & " http://twitter.com/statuses/update.json"
  34.             end if
  35.             growlRegister()
  36.             growlNotify("Tweet Sent", tweet)
  37.         on error
  38.             (* In case curl fails for some reason,  alert us *)
  39.             growlRegister()
  40.             growlNotify("Error", "There was an error sending your tweet.")
  41.         end try
  42.  
  43.     end process text
  44. end using terms from

Breakaway Saves My Ears

I wrote a post a while back about the pesky habit of my MacBook Pro trying to make me go deaf. I plug my laptop into a stereo via the headphone jack at home and listen to music. In order to get the sound levels right at home, I increase the volume to full volume (otherwise I have to turn up the stereo and I get lots of noise and hum). When I leave in the morning, I unplug my laptop and the MacBook resets its volume to the pre-headphone jack volume. Fine. Unfortunately, when I get to work, I plug-in my headphones, start checking email, hit my keyboard command for iTunes play, and proceed to deafen myself with full volume, as the machine automatically resets the system volume to the previous headphone jack volume level.

Today I deafened myself, but upon searching, discovered Alloc Init, which features a nice little app called Breakaway. The main feature of this app is to pause iTunes or launch the screensaver when the headphone jack status is changed (plugged in or out). However, the nicer thing about the app is that it also allows the user to trigger an applescript on the same events. I created the following script called setVolumeTo20of100:

tell application "Finder"
set volume output volume 20
end tell

After creating a custom trigger in Breakaway, my system volume will always be reset to 20 when I plug in something to the headphone jack. Since I don't care about having to increase the volume at home automatically, this is fine for now, since I will most importantly not deafen myself in the morning at work. I will perhaps post an update later that checks the the network preferences for the current location for setting the volume automatically based on location, which will automate things a little more. Meanwhile, I highly recommend this nice little app. (Note: the interface for creating custom triggers is a little clunky, so you may have to play with it a little first, but it does work -- just be patient.)