#!/bin/sh # ####################################### # iTunes Command Line Control v1.0.0.1 # written by David Schlosnagle # created 2001.11.08 # modified 2007.01.28 by David West # modified 2013.08.02 by ootput # filename=itunes #######################################
showHelp () { 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 " 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 " stop = Stop iTunes."; echo " search = Run query, populate playlist named foo and play. " echo " playlist = Show playlists saved in iTunes."; echo " clear = clear playlist foo. "; echo " quit = Quit iTunes."; }
if [ $# = 0 ]; then showHelp; fi
while [ $# -gt 0 ]; do arg=$1; songname=$2; echo $songname; 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 ;;