How to set iChat status from the command line

command lineichatlast.fmmessages

I'm trying to sync my Last.FM last played track with my iChat status… right from the command line. I've come this far:

curl -s http://ws.audioscrobbler.com/1.0/user/Da3X/recenttracks.rss |
    grep -m 1 -E -e "         <title>(.*)</title>.*" |
    sed "s/.*<title>//" |
    sed "s/<\/title>//"

which results in the currently or last played track like

The Black Seeds – Cracks In Our Crown

Is there a way to forward this string as the iChat / Messages status now?

Best Answer

Just found it myself... format the output of sed as AppleScript and call osascript...

curl -s http://ws.audioscrobbler.com/1.0/user/Da3X/recenttracks.rss |
    grep -m 1 -E -e "         <title>(.*)</title>.*" |
    sed "s/.*<title>/tell application \"Messages\" to set the status message to \"♬  /" |
    sed "s/<\/title>/\"/" |
    sed "s/\&amp;/\&/" |
    osascript

That's it!