2

my F8/PlayPause key on Mac OS Catalina (10.15.6) only opens and controls the Music app. Previously, it used to play/pause the active video on Chrome or Safari. This is especially useful for doing coding tutorials on Udemy - I can have the video open in my secondary screen and the text editor/IDE open in my main screen, and can pause/play the video with the pause button.

However, this functionality stopped working about a week ago. At first, the Play/Pause key did nothing. Now, pressing the key will open the Music app if it's not already open, and it only works for that.

I've tried using BetterTouchTool to run an AppleScript script when F5 is pushed that will do the same thing, but nothing happens. The script I tried for Safari is:

tell application "Safari"
  playpause
end tell

but this does absolutely nothing.

Any help here would be good.

1 Answer 1

0

Here is an AppleScript I created for YouTube adapted from this Reddit post. This will pause all YouTube tabs in Safari.

if application "Safari" is running then
    try
        tell application "Safari"
            repeat with t in tabs of windows
                if URL of t contains "youtube.com/watch" then
                    tell t
                        do JavaScript "document.querySelector('[title=\"Pause (k)\"]')?.click();"
                        exit repeat
                    end tell
                end if
            end repeat
        end tell
    end try
end if

When you first run this you'll have to give Apple Scripts permission to control Safari. I also found that I had to select Allow JavaScript from Apple Events in Safari's Develop menu.

For a play/pause behavior (like the the media key), change [title=\"Pause (k)\"] to .ytp-play-button so it reads like this:

document.querySelector('.ytp-play-button')?.click();

You must log in to answer this question.

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