title: Python – Check if Mac is Playing Music
body: <p>I'm trying to write a simple python script to stop the music being played by a Mac. I found some code that emulates the media buttons from the accepted answer here: <a href="https://stackoverflow.com/questions/11045814/emulate-media-key-press-on-mac">emulate media key press on Mac</a>.</p>
  
  <p>Triggering the play/pause button works perfectly, but I only want to do so if there is music currently playing. Otherwise it turns <strong>on</strong> the music (the opposite of what I'm trying to do. Is there any way to get this information from the system?</p>
  
  <p>I need to check if music was actually playing beforehand so I can know whether to resume it later. </p>