Is there a piece of software that allows one to pause (& un-pause) a currently playing YouTube video (or, ideally, any online video/audio media), with a keyboard shortcut or a conveniently accessible button (e.g., a button that sits in the menu bar, located at the top-right of the screen)? The fewer necessary clicks, the better.
The key here is that I want the ability to pause the video in any application, that is, when Google Chrome is not the foremost application (e.g., TextEdit or Microsoft Word is the foremost application).
iOS has this shortcut built-in. If one swipes from the bottom of the screen to the top, media controls appear. These controls can manipulate any and all audio that originates in a Safari tab.
My web browser is Google Chrome.
OS X El Capitan, version 10.11.6.
I would also be open to accomplishing this with an AppleScript (that can then be assigned to a key combination in FastScripts.app). But, I cannot imagine that such a complex task is possible via AppleScript.
Best Answer
********** UPDATED SOLUTION **********
This update is a direct solution to the OP's original question.
This following AppleScript code will add a "Play/Pause YouTube" status menu item with the options to play or pause any YouTube video in either Google Chrome or Safari, whether the browsers are visible or not. Save this following AppleScript code as a "stay open" application in Script Editor.app.
If you want your new... Play Pause YouTube Status Menu.app to only be visible in the status menu and not in the Dock, you can right-click on the app in Finder and select the option to "Show Package Contents". In the Contents folder, open the Info.plist file in any text editor and add the following two lines. Then save and close that file.
If you are not comfortable editing the .plist file directly, this following AppleScript code will allow you to choose the application to hide from the Dock when it is running.
If the chosen application is already set to be hidden from the Dock, the only option you will be given is to unhide the application from being visible in the Dock while it is running… And vice versa.
This script is especially handy for a hiding "stay open applications" with idle handlers' application icons from appearing in the Dock while running.
************ ORIGINAL SOLUTION ************
This script will click on the Play/Pause button on a video playing in YouTube in Google Chrome, whether or not Google Chrome is visible.
This is the script version to work with Safari
In an effort to give the OP A complete AppleScript solution, I have taken my original answer one step further..
UPDATE
I finally figured it out. I created an AppleScript application in Xcode. Originally, my project only started with a one button window to control YouTube videos currently active in Chrome or Safari. This project has grown a little bit into an application that contains several utilities. This GIF shows the YouTube Pause button controlling YouTube in Chrome and Safari. I linked the button actions to the AppleScript I originally wrote in script editor.
This is a snapshot of the Xcode application Working in the AppDelegate.applescript file.
Here is the code in that file I created to make the program work.
I updated the code so that the YouTube tab in Chrome doesn't need to be the visible or active tab when clicking the YouTube Pause Button created in Xcode
Here is a link to download the entire Xcode project
WARNING: The desktop screen saver function will freeze the App. After force quit and re-open, The desktop screensaver function to exit active screen saver will work.
Afterthoughts: I probably should have wrapped each of the AppleScript codes in "try" statements to avoid all sorts of error messages for those playing with this project,who don't have the same system and computer type that I do. (MacBook Pro 15" OS Sierra 10.12.6)
For the zoom function To work, it must be enabled in system preferences.
For the toggling of “Dictation on/off” to function correctly, the short cut to enable dictation commands in system preferences must match the shortcut used in the script
Currently I am working on the ability to toggle between the application running windowed or menu bar only