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?
3 Answers
You can control iTunes using AppleScript:
tell application "iTunes" to play
To run it directly from Terminal command line, you can use osascript:
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?
- 546
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.
- 115,663
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:
https://github.com/mischah/itunes-remote
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
- 11
-
2
-
– user3439894 Mar 23 '18 at 20:41osascript -e 'tell application "iTunes" to play'still works in macOS High Sierra 10.13.3 without issue! 2. Please do not make statements such as "osascript is depreciated in macOS 10.13 (high sierra)" without including the canonical source of such a statement. -
Something can be deprecated, and still work; but I believe that osascript is NOT deprecated. (Nor has it depreciated in value.) – benwiggy Jun 11 '20 at 13:31
osascript -e 'tell application "Spotify" to play'– Eduardo Pereira Mar 12 '23 at 12:34