Skip to content

Instantly share code, notes, and snippets.

@ChristoferK
Last active June 17, 2018 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChristoferK/c56a8b03c755b1fd97151105e48034b7 to your computer and use it in GitHub Desktop.
Save ChristoferK/c56a8b03c755b1fd97151105e48034b7 to your computer and use it in GitHub Desktop.
[YouTube Video State] Returns `playing`, `paused`, or `ended` to signify the state of a YouTube video open in Safari browser #AppleScript #YouTube #video #playing #Safari #JavaScript
tell application "Safari" to tell front window to tell ¬
(first tab whose URL contains "youtube.com/watch?v=") to ¬
if it exists then do JavaScript [¬
"document", ¬
".querySelector('div[class*=\"-mode\"]')", ¬
".className", ¬
".match(/(playing|paused|ended)-mode/)[1]"] as text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment