uɐʎɹ ррoʇ uɐʎɹ bio photo

uɐʎɹ ррoʇ uɐʎɹ

Hello. Is is me you're looking for?
僕は猿ーロボット。
robotic life signs.
makes noise, hears sounds, intafon.
affe auf deux roues.

Email Github Github Gist Last.fm Soundcloud Flickr

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:

using terms from application "GrowlHelperApp"
	-- Register Growl
	on growlRegister()
		tell application "GrowlHelperApp"
			register as application "Tweet" all notifications {"Alert"} default notifications {"Alert"} icon of application "Quicksilver.app"
		end tell
	end growlRegister

	-- Notify using Growl
	-- Example: growlNotify("This is an Alert","This is a test of the Growl Alert System")
	on growlNotify(grrTitle, grrDescription)
		tell application "GrowlHelperApp"
			notify with name "Alert" title grrTitle description grrDescription application name "Tweet"
		end tell
	end growlNotify
end using terms from

using terms from application "Quicksilver"
	on process text tweet
		tell application "Keychain Scripting"
			set twitter_key to first Internet key of current keychain whose server is "twitter.com"
			set twitter_login to quoted form of (account of twitter_key & ":" & password of twitter_key)
		end tell
		set twitter_status to quoted form of ("status=" & tweet)

                -- I have proxy-config in a directory "~/bin"
		set the_proxy to do shell script "~/bin/proxy-config -h"

		try
			if (the_proxy = "") then
				set results to do shell script "curl --user " & twitter_login & " --data-binary " & twitter_status & " http://twitter.com/statuses/update.json"
			else
				set results to do shell script "curl --proxy " & the_proxy & " --user " & twitter_login & " --data-binary " & twitter_status & " http://twitter.com/statuses/update.json"
			end if
			growlRegister()
			growlNotify("Tweet Sent", tweet)
		on error
			(* In case curl fails for some reason,  alert us *)
			growlRegister()
			growlNotify("Error", "There was an error sending your tweet.")
		end try

	end process text
end using terms from