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

Recent Posts

Popular Posts

See what I hear [updated]

13th January, 2003  |  2 Comments

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]:



#!/bin/sh

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
else
echo "nothing" > /tmp/itunes.txt
fi
curl -u login:password -T /tmp/itunes.txt ftp://website.domain/
fi

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 »

2 Comments

Chris

10th March, 2005

Here's a condensed way to get what's playing in iTunes:

<pre>osascript -e &#39;tell application "iTunes" to (artist of current track) & " - " & (name of current track)&#39;</pre>

You can also use AppleScript to check for the existence of running iTunes with the following:

<pre>osascript -e &#39;tell application "Finder" to (get name of processes contains "iTunes")&#39;</pre>

That will return the text "true" if iTunes is running.

Maybe one or the other (or both!) will be of use to you. I use them in a shell script that can control iTunes and report status information, so it helps reduce the confusion of wrapping lines of -e &#39;&#39; -e &#39;&#39; etc :)


club60.org

10th March, 2005

A bit faster way to check if iTunes is running:
if ($(test $(ps -x | grep /Applications/iTunes.app/Contents/MacOS/iTunes | wc -l) -eq " 2"))


Post A Comment

You need JavaScript to post comments.