I want to control my media player (iTunes, Spotify, etc) using terminal. My goal was simply to trigger press on play/pause button using script. Is that possible?
You can control iTunes using AppleScript:
tell application "iTunes" to play
To run it directly from Terminal command line, you can use
osascript -e 'tell application "iTunes" to play'
To figure out what commands are available in iTunes, use the ScriptEditor app and open the dictionary of iTunes, see How do I find out the applescript commands available for a particular app?
I'm not certain about Spotify etc, but for iTunes if Doug's Applescripts for iTunes can't do it, it probably can't be done. It's got to be the longest running & most comprehensive site for all things iTunes.
If that's not enough, there are half a dozen apps too.
osascript is depreciated in macOS 10.13 (high sierra) making the previous solutions unusable.
mischah has created a nice commandline that can be used to control (and search!) itunes from the commandline:
it doesnt do Shuffle or Volume - but you can search, play, stop, next from the terminal. 🎶
i had to do brew install npm - to get it to compile, but brew is quite well supported in the terminal, and this provides a more than acceptable alternative to the lack of osascripting of itunes.
cheers from toronto island, jp