Pause/Play YouTube Video Running in Background

I love to listen to YouTube videos like Podcasts while working. I bet many people do have this habit.

    to clickClassName(theClassName, elementnum)
	tell application "Google Chrome" to (tabs of window 1 whose URL contains "youtube")
	set youtubeTabs to item 1 of the result
	tell application "Google Chrome"
		execute youtubeTabs javascript "document.getElementsByClassName('" & theClassName & "')[" & elementnum & "].click();"
	end tell
end clickClassName

clickClassName("ytp-play-button ytp-button", 0)

The above AppleScript is for Google Chrome.

Source: https://apple.stackexchange.com/questions/281483/how-to-pause-youtube-video-via-keyboard-shortcut-or-from-menu-bar/281567

2 Likes