Hi everyone,
I found online a script someone had written that allows you to control your itunes from the command-line, which is very useful for me as I can ssh to my main computer (which has airtunes via airport express) from my laptop and start and stop certain playlists…
Anyway, I added something to the script to have it return all of my playlists to the command line so I can know which ones that I can switch to…
right now, they are being returned like a normal list would be “depeche mode, new order, xymox” etc… And I was wondering if anyone knows a good way that I can have then returned in a 3 column view spaced out… like:
“depeche mode new order xymox”
I tried doing something with text item delimiters, but it wasn’t working very well with the osascript -e stuff…
Any thoughts?
here is the script:
#!/bin/sh
####################################
iTunes Command Line Control v1.0
written by David Schlosnagle
created 2001.11.08
####################################
showHelp () {
echo “-----------------------------”;
echo “iTunes Command Line Interface”;
echo “-----------------------------”;
echo “Usage: basename $0
”;
echo;
echo “Options:”;
echo “-----------------------------”;
echo “iTunes Command Line Interface”;
echo “-----------------------------”;
echo “Usage: basename $0
”;
echo;
echo “Options:”;
echo " status = Shows iTunes’ status, current artist and track.“;
echo " play = Start playing iTunes.”;
echo " pause = Pause iTunes.“;
echo " stop = Stop iTunes.”;
echo " next = Go to the next track.“;
echo " prev = Go to the previous track.”;
echo " mute = Mute iTunes’ volume.“;
echo " unmute = Unmute iTunes’ volume.”;
echo " vol up = Increase iTunes’ volume by 10%“;
echo " vol down = Increase iTunes’ volume by 10%”;
echo " vol # = Set iTunes’ volume to # [0-100]“;
echo " playlist “@” = Play iTunes’ playlist named @”;
echo " list = Display all playlist names";
echo " shuffle = Shuffle current playlist.“;
echo " shuffleoff = Stop shuffling current playlist.”;
echo " quit = Quit iTunes.";
}
if [ $# = 0 ]; then
showHelp;
fi
while [ $# -gt 0 ]; do
arg=$1;
case $arg in
case $arg in
“status” ) state=osascript -e 'tell application "iTunes" to player state as string'
;
echo “iTunes is currently $state.”;
if [ $state = “playing” ]; then
artist=osascript -e 'tell application "iTunes" to artist of current track as string'
;
track=osascript -e 'tell application "iTunes" to name of current track as string'
;
echo “Current track $artist: $track”;
fi
break ;;
"play" ) echo "Playing iTunes.";
osascript -e 'tell application "iTunes" to play';
break ;;
"pause" ) echo "Pausing iTunes.";
osascript -e 'tell application "iTunes" to pause';
break ;;
"next" ) echo "Going to next track." ;
osascript -e 'tell application "iTunes" to next track';
break ;;
"prev" ) echo "Going to previous track.";
osascript -e 'tell application "iTunes" to previous track';
break ;;
"mute" ) echo "Muting iTunes volume level.";
osascript -e 'tell application "iTunes" to set mute to true';
break ;;
"unmute" ) echo "Unmuting iTunes volume level.";
osascript -e 'tell application "iTunes" to set mute to false';
break ;;
"vol" ) echo "Changing iTunes volume level.";
vol=`osascript -e 'tell application "iTunes" to sound volume as integer'`;
if [ $2 = "up" ]; then
newvol=$(( vol+10 ));
fi
if [ $2 = "down" ]; then
newvol=$(( vol-10 ));
fi
if [ $2 -gt 0 ]; then
newvol=$2;
fi
osascript -e "tell application \"iTunes\" to set sound volume to $newvol";
break ;;
"shuffle" ) echo "Shuffle is ON.";
osascript -e 'tell application "iTunes" to set shuffle of current playlist to 1';
break ;;
"shuffleoff" ) echo "Shuffle is OFF.";
osascript -e 'tell application "iTunes" to set shuffle of current playlist to 0';
break ;;
"list" ) osascript -e "tell application \"iTunes\" to return name of playlists";
break ;;
"playlist" ) echo "Changing iTunes playlist."; osascript -e 'tell application "iTunes"' -e "set the new_playlist to \"$2\" as string" -e "play playlist new_playlist" -e "end tell"; break ;;
"stop" ) echo "Stopping iTunes.";
osascript -e 'tell application "iTunes" to stop';
break ;;
"quit" ) echo "Quitting iTunes.";
osascript -e 'tell application "iTunes" to quit';
exit 1 ;;
"help" | * ) echo "help:";
showHelp;
break ;;
esac
done
hi partick,
I’d suggest using awk - something like this:
"list" ) osascript -e "tell application \"iTunes\" to return name of playlists" | perl -pe 's/, /\n/g' | awk -F'\n' '
BEGIN {nl=1}
{if (nl == 3)
{printf "%-50s\n",substr($1,1,48);
nl=1}
else
{printf "%-50s",substr($1,1,48);
nl++}
next}';
break ;;
Hope that helps
D.