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?

4 Answers 4


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?


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
    Commented Mar 2, 2016 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
    Commented Mar 2, 2016 at 20:04
  • It works for Spotify as well, you can use osascript -e 'tell application "Spotify" to play' Commented Mar 12, 2023 at 12:34

You could write a python script to press the pause/ play, next and previous buttons using pyautogui. The buttons have codes appointed to them that you can find online.

  • This answer would be way more useful if you actually include the Python code required.
    – nohillside
    Commented Apr 13 at 14:12

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

  • 2
    Do you have a source for osascript being deprecated?
    – grg
    Commented Mar 23, 2018 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. Commented Mar 23, 2018 at 20:41
  • Something can be deprecated, and still work; but I believe that osascript is NOT deprecated. (Nor has it depreciated in value.)
    – benwiggy
    Commented Jun 11, 2020 at 13:31

You must log in to answer this question.

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