Created
August 11, 2011 19:23
-
-
Save damog/1140514 to your computer and use it in GitHub Desktop.
Spotify to iChat and Adium statuses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# shamelessly taken from: http://webcache.googleusercontent.com/search?q=cache:aUG0MH-OLaEJ:codesnippets.joyent.com/posts/show/1954+spotify+ichat&cd=1&hl=en&ct=clnk&gl=us&source=www.google.com | |
# messages have this format: | |
# 'Mon Jul 5 13:25:05 azeef-macbook GrowlHelperApp[46245] <Warning>: Spotify: Do the Buildings and Cops Make You Smile? (Bedroom Walls\nThe 4400) - Priority 0' | |
# which this script extracts as: | |
# 'Spotify: Do the Buildings and Cops Make You Smile? (Bedroom Walls' | |
# 'The 4400)' | |
# or (a little more abstract): | |
# '$song ($artist' | |
# '$album)' | |
# where $song = 'Spotify: $title' | |
# The status will be set to 'Spotify: $title - $artist ($album)', dive into the code to change that ;-) | |
syslog -F '$Message' -w 1 -k Sender GrowlHelperApp | while read first | |
do | |
if [ -n "`echo $first | egrep '^Spotify: '`" ]; then | |
# line starts with 'Spotify: ', so read second line | |
read second | |
# if you don't want the 'Spotify: ', uncomment the following line: | |
first=${first/Spotify: /} | |
# extract song, artist and album | |
song=${first% (*} # reads 'Spotify: $title' from 'Spotify: $title ($artist' | |
artist=${first##* (} # reads '$artist' from 'Spotify: $title ($artist' | |
album=${second%%)*} # reads '$album' from '$album)' | |
# this part makes sure no ads or spotify messages are posted as your status | |
# the test reads: | |
# - either the artist equals 'Spotify' (the x's cancel out) or | |
# - the album's length is at least 8 (the length of the string 'spotify:') and it starts with 'spotify:' | |
# this works, because Spotify plays it's messages with the artist 'Spotify' | |
# and (almost all) ads have a link which starts with 'spotify:' embbedded as the album | |
if [ "x$artist" = 'xSpotify' -o ${#album} -ge 8 -a "${album:0:8}" = 'spotify:' ]; then | |
continue # skip this message if it's an ad | |
fi | |
status="$song - $artist ($album)" | |
echo $status | |
echo | osascript <<EOF | |
tell application "System Events" | |
if exists process "iChat" then tell application "iChat" to set the status message to "$status" | |
if exists process "Adium" then tell application "Adium" to set status message of every account to "$status" | |
end tell | |
EOF | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
run as a bash script. if you don't know how to do that, I cannot help you.