Saturday, July 05, 2008

AppleScripting Twitter in Quicksilver

Today I woke up with a strange need to show some love to my everyday helper, Quicksilver. And just as I was about to twit something, I realize that was the perfect addition I was lacking! Let's see what I've come up with.

I found out Tweet.scpt from Ted Leung, an AppleScript to send Twitts via Quicksilver. As simple as that. Drawbacks, Twitter only lets us send 140 characters long messages, and Quicksilver won't count that in the interface for us. Also, inline text writing in the default QS interface is not exactly great looking. For the UI issue all I had to do is to grab the BezelHUD skin from Julius Eckert. Just trust me on that one, see the video on his page or go ahead and install it - I'm not going back, it's awesome!

To the char count problem, I had to make some modifications to the script. In short, I opted to count the chars using

count characters of tweet

then either send the message to twitter or show a dialog warning telling you have exceeded the char limit. Pretty simple, and works almost great (bonus for finding how quicksilver could show the char count in the text-edit window!).
All the notifications use Growl. And the script looks for your Twitter account info in your Keychain, using the Usable Keychain Scripting addition, from Daniel Jalkut (another small modification from the original script, that uses the Apple's slow Keychain Scripting...). But I found out the Keychain thing was being blocked if it wasn't started yet. So I "borrowed" this loader (I can't remember where...), and call it before I try to access my password, and it works great:

on startKeychainScripting()

-- This function ensures that the Keychain Scripting.app is launched by a process

-- different from the one executing this script. It is only needed when using Keychain Scripting to

-- retrieve the password property of a key.

-- Quit Keychain Scripting if it's running, since opening this script may have implicitly launched it.

try

tell application "System Events"

set foundApp to first process whose name is "Keychain Scripting"

set pid to id of foundApp -- this will exit the try block if the process isn't running

quit foundApp -- we get here if the process is found

end tell

end try

-- get Finder to launch Keychain Scripting

tell application "Finder"

open application file ((path to home folder as string) & "Library:ScriptingAdditions:Usable Keychain Scripting") as alias

end tell

-- make sure that Keychain Scripting is up and running

repeat while true

try

tell application "System Events"

set foundApp to first process whose name is "Usable Keychain Scripting"

set pid to id of foundApp -- this will exit the try block if the process isn't running

end tell

exit repeat -- we get here if the process is found

end try

end repeat

end startKeychainScripting


This is also included in my script. All you have to do is to place it in ((path to home folder as string) & "Library:ScriptingAdditions:Usable Keychain Scripting") and reload Quicksilver. Try it out!

Now all I have to do is to find out why direct messages like "d username hey, what's up" don't get their destiny :( Maybe it has something to do with http://twitter.com/statuses/update.json not liking direct messages, but my spare time is up now, I'll give this another try later on...

Last, but not least, many thanks to all authors and contributors of all software and tips I've mentioned in this post! :)

1 comments:

Bruno said...

Wow. Yeah, BezelHUD just got another fan.
The new text edit window won me over, completely