Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here is what I want to do: hook up a keyboard shortcut with an action to play/pause the video that is currently open in a Google Chrome tab. Would it be possible on Mac OS X?

I was thinking about keeping Youtube always in a particular tab (e.g. the first one) and creating Automator script with a keyboard shortcut. I know it would be possible by simulating user actions (switch to particular tab, simulate click, go back to last tab) but I'm looking for more smooth way.

share|improve this question
up vote 2 down vote accepted

You could assign a shortcut to a script like this:

tell application "Google Chrome"
    repeat with t in tabs of windows
        tell t
            if URL starts with "" then
                execute javascript "player = document.querySelectorAll('#watch7-player embed')[0]
if (player) {
    player.getPlayerState() == 1 ? player.pauseVideo() : player.playVideo()
} else { // if is enabled
    document.querySelectorAll('.html5-player-chrome > button:first-child')[0].click()
                exit repeat
            end if
        end tell
    end repeat
end tell

For Safari, replace execute javascript with do JavaScript.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.