Creation: 14/07/2009 17:22
Last Modification: 18/07/2009 17:59
With MAC OS X, a wonderfull command line program named "osascript"
is avaiable.
Using osascript you can command almost every graphical program in
command line and i will show you how to use it to command itunes
(which will make it possible to run those commands in an ssh session).
To start itunes:
osascript -e 'tell application "iTunes" to activate'
To jump to next track:
osascript -e 'tell application "iTunes" to next track'
Replacing "next track" in the last command you can:
- pause : pause playing
- play : start playing
- previous track : return to previous track.
Using this i made a small script to start itunes if needed and execute
the wanting command:
#!/bin/bash
mycmd=$(basename $0)
isStarted=$(osascript -e 'tell application "System Events" to (name of processes) contains "iTunes"')
if [ "$isStarted" = "false" ]; then
osascript -e 'tell application "iTunes" to activate'
fi
case $mycmd in
itunes_next)
osascript -e 'tell application "iTunes" to next track'
;;
itunes_pause)
osascript -e 'tell application "iTunes" to pause'
;;
itunes_play)
osascript -e 'tell application "iTunes" to play'
;;
itunes_prev)
osascript -e 'tell application "iTunes" to previous track'
;;
esac
You then need to link this script to the itunes_next, itunes_pause,
itunes_play and itunes_prev and you are good to go.