1

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?

1

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?

0

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.

  • Yup, that one using apple script. Thats why I want to trigger the play/pause button. My idea, maybe, just maybe, we could trigger the hex code of the button. kbdedit.com/manual/low_level_vk_list.html – rahmat Mar 2 '16 at 20:02
  • Why do you need to do it from Terminal? Would it not be easier to set up the script as a Service & hot-key it? – Tetsujin Mar 2 '16 at 20:04
-2

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

  • 2
    Do you have a source for osascript being deprecated? – grg Mar 23 '18 at 18:17
  • 1. osascript -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. – user3439894 Mar 23 '18 at 20:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .