A PHP Developer's Blog - Joakim Nygård

About jokke.dk

jokke.dk is the personal website of , a software architect, entrepeneur and Mac user living in Copenhagen, Denmark. Read more »

Search the Site

See what I hear [updated]

13th January, 2003

I've put an experimental feature on my site today. Inspired by KungTunes, an AppleScript Studio application [amazing technology if a little slow] and decided to build the same functionality using only the terminal - I figured it would be lighter on my machine. So, here it is, now you can see what I'm hearing in iTunes just below the logo.
I made it with osascript [a command line program to execute applescripts], bash, curl and crontab - and of course php to finally print it on the webpage. Here's what the shell script [remember to chmod 755 it] looks like [the updated script checks for an active network interface]:


if [`ifconfig -a|grep 'status: active'|wc -l`]; then
song=`osascript -e 'tell application "iTunes"' -e 'the player state is playing' -e 'end tell'`

if [$song = 'true']; then
osascript -e 'tell application "iTunes"' -e 'return (artist of current track) & " - " & (name of current track)' -e 'end tell' > /tmp/itunes.txt
echo "nothing" > /tmp/itunes.txt
curl -u login:password -T /tmp/itunes.txt ftp://website.domain/

I apologize for the formatting, the pre-tag doesn't wrap the lines so I can't use that. Anyway, it does require some unix skills but I will gladly post more detailed instructions if someone is interested. The above code is then executed every 2 minutes [might need adjustment] by crontab. Then I can simply include the uploaded file with php on this site. Pretty neat.

« 15 Minutes of Fame  –  Plans for February »