Controlling iTunes from the OSX terminal

There are several things you can do with iTunes in the OSX terminal.

Get the currently playing track name:

osascript -e 'tell application "iTunes" to name of current track as string'

Get the currently playing artist name:

osascript -e 'tell application "iTunes" to artist of current track as string'

Play the next song:

osascript -e 'tell application "iTunes" to next track'

Play the previous song:

osascript -e 'tell application "iTunes" to next track'

Pause playback:

osascript -e 'tell application "iTunes" to pause'

Resume playback:

osascript -e 'tell application "iTunes" to play'

Mute playback:

osascript -e 'tell application "iTunes" to set mute to true'

Unmute playback:

osascript -e 'tell application "iTunes" to set mute to true'

Quit iTunes:

osascript -e 'tell application "iTunes" to quit'
Written on November 13, 2014