soeren says

More status updating goodness

August 6th, 2007

Regarding my script from two weeks ago that updates your status on instant messengers and web services simultaneously, a few amendments:

  1. As Zib points out in a comment, it is indeed possible to adjust the script for fewer services. For example, removing the tell application "Skype" block will leave out the Skype aspect, and only update Adium, Facebook and Twitter.
  2. It is also possible to integrate this with Growl, so you can get some feedback on when it’s done updating each service. Note that this isn’t necessarily a guarantee that this update actually succeeded; for instance, I at first had a bug where Growl would happily report having updated Facebook’s status, even when Facebook showed no change at all: this notification only refers to a finished attempt.
  3. And finally, I admittedly did something lazy by not properly fetching a post_form_id from Facebook, instead opting to hardcode it. That worked fine for me for a few days, but I eventually had to fix it on my end, and this may very well be the reason it never worked for Christopher. My revised version, as posted below, should remedy this (it has worked for me since).

So with all that said, here’s my current version of the script:

using terms from application "Quicksilver"
	on process text NewStatus
		tell application "GrowlHelperApp" to register as application "StatusUpdater" all notifications {"AdiumStatusUpdated", "SkypeStatusUpdated", "TwitterStatusUpdated", "FacebookStatusUpdated"} default notifications {"AdiumStatusUpdated", "SkypeStatusUpdated", "TwitterStatusUpdated", "FacebookStatusUpdated"}
		tell application "Adium" to set my status message to NewStatus
		tell application "GrowlHelperApp" to notify with name "AdiumStatusUpdated" title "Adium status updated" description NewStatus application name "StatusUpdater" icon of application "Adium"
		tell application "Skype" to send command "SET PROFILE MOOD_TEXT " & NewStatus script name "Quicksilver StatusUpdater"
		tell application "GrowlHelperApp" to notify with name "SkypeStatusUpdated" title "Skype status updated" description NewStatus application name "StatusUpdater" icon of application "Skype"
		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=" & NewStatus)
		do shell script "curl --user " & twitter_login & " --data-binary " & twitter_status & " http://twitter.com/statuses/update.json"
		tell application "GrowlHelperApp" to notify with name "TwitterStatusUpdated" title "Twitter status updated" description NewStatus application name "StatusUpdater" icon of application "Twitterrific"
		tell application "Keychain Scripting"
			set facebook_key to first Internet key of current keychain whose server is "login.facebook.com"
			set facebook_username to account of facebook_key
			set facebook_password to password of facebook_key
		end tell
		set facebook_form_id to do shell script "curl -v -k -d email='" & facebook_username & "' -d pass='" & facebook_password & "' -d login=Login -L 'https://login.facebook.com/login.php?m&next=http%3A%2F%2Fm.facebook.com%2Fhome.php' -A 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3' --cookie-jar /tmp/facebook-cookie.txt | tr '\\"' '
' | grep -A 2 post_form_id | tail -1"
		do shell script "curl -v -d post_form_id=" & facebook_form_id & " -d status='" & NewStatus & "' -d update='Update' -A 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3' --cookie /tmp/facebook-cookie.txt 'http://m.facebook.com/home.php' -L"
		tell application "GrowlHelperApp" to notify with name "FacebookStatusUpdated" title "Facebook status updated" description NewStatus application name "StatusUpdater" icon of application "FMenu"
	end process text
end using terms from

If you don’t want Growl support (shouldn’t make much of a performance difference, however) or don’t have Growl installed, you’ll want to cut out each line starting with tell application "GrowlHelperApp", like so:

using terms from application "Quicksilver"
	on process text NewStatus
		tell application "Adium" to set my status message to NewStatus
		tell application "Skype" to send command "SET PROFILE MOOD_TEXT " & NewStatus script name "Quicksilver StatusUpdater"
		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=" & NewStatus)
		do shell script "curl --user " & twitter_login & " --data-binary " & twitter_status & " http://twitter.com/statuses/update.json"
		tell application "Keychain Scripting"
			set facebook_key to first Internet key of current keychain whose server is "login.facebook.com"
			set facebook_username to account of facebook_key
			set facebook_password to password of facebook_key
		end tell
		set facebook_form_id to do shell script "curl -v -k -d email='" & facebook_username & "' -d pass='" & facebook_password & "' -d login=Login -L 'https://login.facebook.com/login.php?m&next=http%3A%2F%2Fm.facebook.com%2Fhome.php' -A 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3' --cookie-jar /tmp/facebook-cookie.txt | tr '\\"' '
' | grep -A 2 post_form_id | tail -1"
		do shell script "curl -v -d post_form_id=" & facebook_form_id & " -d status='" & NewStatus & "' -d update='Update' -A 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3' --cookie /tmp/facebook-cookie.txt 'http://m.facebook.com/home.php' -L"
	end process text
end using terms from

If you want Skype removed, you get rid of this line:

tell application "Skype" to send command "SET PROFILE MOOD_TEXT " & NewStatus script name "Quicksilver StatusUpdater"

(And the Growl one underneath no longer makes sense either, of course.)
In case of removing Twitter or Facebook, you’ll also want to remove the respective tell application "Keychain Scripting" preceding it, up until and including end tell.

Enjoy!

Posted in AppleScript, Mac, Programming, Web

Share

Others' Thoughts

# Tom

Pretty nice script. I don’t really have time to go over the code myself, but copy and pasting into the ScriptEditor returns the error “Expected end of line, etc. but found unknown token.” Since I’m not really familiar with AppleScript, I can’t tell if there is something obviously missing :/ Any thoughts?

# chucker

Fixed. WordPress was messing with my code. :-/

# Kevin Kuchta

I’m trying to write a few programs around changing facebook status, and I can’t seem to get them to work. I figured I’d try ot get something prewritten to work, but I can’t seem to make yours do it. I really have no familiarity with applescript, any chance I could get you to tell me why this isn’t working?

using terms from application "Quicksilver" on process text NewStatus tell application "Keychain Scripting" set facebookkey to first Internet key of current keychain whose server is “login.facebook.com” set facebookusername to account of facebookkey set facebookpassword to password of facebookkey end tell set facebookformid to do shell script “curl -v -k -d email=’” & facebookusername & “‘ -d pass=’” & facebookpassword & “‘ -d login=Login -L ‘https://login.facebook.com/login.php?m&next=http%3A%2F%2Fm.facebook.com%2Fhome.php’ -A ‘Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3′ –cookie-jar /tmp/facebook-cookie.txt | tr ‘\”‘ ‘ ‘ | grep -A 2 postformid | tail -1″ do shell script “curl -v -d postformid=” & facebookform_id & ” -d status=’” & NewStatus & “‘ -d update=’Update’ -A ‘Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3′ –cookie /tmp/facebook-cookie.txt ‘http://m.facebook.com/home.php’ -L” end process text end using terms from

Thanks,

-Kevin

# Kevin Kuchta

Should have mentioned this previously, all I did was remove the growl, adium, skype, and twitter sections.

# chucker

I just tested your code, and it works for me. Keep in mind that the script is for Quicksilver, not stand-alone, so you use it as described in the final paragraph here.

# Kevin Kuchta

Strange indeed. I did run it in QS as described. I guess I’ll have to troubleshoot this on my end. :/

# Kevin Kuchta

If it’s not too much trouble, I’m wondering what version of the OS and of Quicksilver you’re running, as I’ve tried this on 3 separate machines with no success. I’m not even getting the keychain authentication boxes.

# chucker

You can try hardcoding the username and password and work from there, just to see if the issue is with Keychain Scripting. (And then you could try with Jalkut’s “Usable Keychain Scripting”.)

My OS is 10.4.10 (build 8R2232; Intel), and Quicksilver is at Beta 51 (build 3800).

# Kevin Kuchta

Excellent; removing the keychain code did the trick. Now I finally have a baseline bit of working code that I can expand on. I’ve been trying to get Java to pull this trick so that I can write some gui-ful apps around it (java, because I’m comparatively new at software development, and it’s the only language I can code gui in).

Anyways, thank you for the help. Do you mind if I post this around in a few place, with credit given?

# chucker

I don’t mind at all. Go ahead and share the knowledge. :-)

# Christopher Miles

I’m going to try to hard code my account details for Twitter and Facebook because I can only get Adium to work at this point.

How would I do this? What’s the syntax?

ie. what code would I use instead of: set facebookusername to account of facebookkey set facebookpassword to password of facebookkey

# chucker
set facebook_username to "exampleUser"
set facebook_password to "340asdI2B"

That should do.

# Christian Flickinger

Great use of the code! Thanks for mentioning me in the original post as well!

# Norman Walsh

Hmm. FaceBook doesn’t seem to work and a little debugging suggests that “postformid” no longer appears in the first page curl’d. Does it still work for you?

# chucker

Nope, it sadly broke a while ago. I haven’t had a chance to look into it yet. Looks like there’s some legal goings-on, too.

# Norman Walsh

Yes, I saw that later in the day. I’ll likely walk away and never look back. A “social web” site with anti-social tendancies. There’s irony there somewhere, I’m sure.

Your Own Thoughts

I'd love to hear your input. Just try to stick to a few rules:

Before you comment for the first time (or, after you have deleted cookies), you will have to answer a little challenge to prove that you are not a spammer.

Comments are written in Markdown.

Leave the country the same, but correct the continent, and end the sentence with a period instead.