Playing/Pausing iTunes while another app plays media While browsing on Safari and listening to iTunes I come across a video and then press the "play" button on the keyboard (to stop the music while I watch the video) it starts/stops the video instead of the music (I have no control over the music).

How can I quickly play/pause my music without affecting the video?
If you're not averse to downloading some of the most useful software I've ever installed you can set the play/pause button (on my keyboard fn+F8) to always control iTunes using Karabiner-Elements.

Just add something like the following rule to ~/.config/karabiner/karabiner.json

{  
   "description": "Play/pause button should only control iTunes.",
   "manipulators": [  
      {  
         "from": {  
            "key_code": "f8",
            "modifiers": {  
               "mandatory": [  
                  "fn"
               ]
            }
         },
         "to": [  
            {  
               "shell_command": "osascript -e 'tell application \"iTunes\" to playpause'"
            }
         ],
         "type": "basic"
      }
   ]
}


You may remove the "modifiers" part if you normally press F8 without pressing fn to play/pause iTunes.

Then in Karabiner-Elements you'd add your new rule as a complex modification: