I've set up a G4 Cube as an iTunes server (VCR, movie player, backup server, etc.) connected to an LCD TV, and I use an ATI Remote Wonder to control iTunes. The problem is that i find it quite uncomfortable to select a playlist with the Remote Wonder's cursor. You have to scroll the list down (move the cursor to the scroll bar), then select a playlist (move the cursor to the playlist).
So I thought I would write a script to ease the task of selecting a playlist. This script can easily be extended to allow the selection of a movie (or any other file).
#!/bin/sh
# get the playlists:
echo `/usr/bin/osascript << END | tr "," "\n" > playlists.tmp
try
tell application "iTunes"
set the_playlists to the name of every playlist
end tell
end try
END
`
# get single characters (without the need to press enter) from std-in:
getc (){
stty raw
eval $1=`dd bs=1 count=1 2>/dev/null`
stty cooked
}
cat playlists.tmp
# convert numbers to characters
while [[ $EXIT != "true" ]]; do
getc CHARACTER
clear
case $CHARACTER in
1)
CHARACTER="[.]"
;;
2)
CHARACTER="[2ABCabc]"
;;
3)
CHARACTER="[3DEFdef]"
;;
4)
CHARACTER="[4GHIghi]"
;;
5)
CHARACTER="[5JKLjkl]"
;;
6)
CHARACTER="[6MNOmno]"
;;
7)
CHARACTER="[7PQRSpqrs]"
;;
8)
CHARACTER="[8TUVtuv]"
;;
9)
CHARACTER="[9WXYZwxyz]"
;;
0)
CHARACTER="[0 _-]"
;;
q)
exit
;;
esac
SEARCH=${SEARCH}${CHARACTER}
if [[ `grep -i "$SEARCH" playlists.tmp | wc -l` == " 1" ]]; then
PLAYLIST=`grep -i "$SEARCH" playlists.tmp | perl -pe 's/^+[\t ]//g'`
EXIT="true"
elif [[ `grep -i "$SEARCH" playlists.tmp | wc -l` == " 0" ]]; then
SEARCH=""
fi
grep -i "$SEARCH" playlists.tmp | tr '[A-Z]' '[a-z]' | sed s/"\($SEARCH\)"/"[\1]"/
done
echo "--------"
echo $PLAYLIST
echo "--------"
/usr/bin/osascript << END
tell application "iTunes"
set the_playlist to item 1 of (every playlist whose name is "$PLAYLIST")
play track 1 of the_playlist
end tell
tell application "iTunes" to activate
END
sh $0
Mac OS X Hints
http://hints.macworld.com/article.php?story=2006042803145949