Skip to content

Instantly share code, notes, and snippets.

@zachloubier
Created December 3, 2015 01:05
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save zachloubier/9b07fd21292a7dfb92d9 to your computer and use it in GitHub Desktop.
Save zachloubier/9b07fd21292a7dfb92d9 to your computer and use it in GitHub Desktop.
Scripts for controlling YouTube videos. Inspiration taken from https://gist.github.com/fent/7763775
# Next Youtube Video in Playlist
tell application "Google Chrome"
repeat with t in tabs of windows
tell t
if URL starts with "http://www.youtube.com/watch" or URL starts with "https://www.youtube.com/watch" then
execute javascript "
var player = document.getElementById('movie_player') || document.getElementsByTagName('embed')[0];
if (player) {
document.getElementsByClassName('ytp-next-button')[0].click()
}
"
exit repeat
end if
end tell
end repeat
end tell
# Play or pause a video.
tell application "Google Chrome"
repeat with t in tabs of windows
tell t
if URL starts with "http://www.youtube.com/watch" or URL starts with "https://www.youtube.com/watch" then
execute javascript "
var player = document.getElementById('movie_player') || document.getElementsByTagName('embed')[0];
if (player) {
document.getElementsByClassName('ytp-play-button')[0].click()
}
"
exit repeat
end if
end tell
end repeat
end tell
# Previous Youtube Video in Playlist
tell application "Google Chrome"
repeat with t in tabs of windows
tell t
if URL starts with "http://www.youtube.com/watch" or URL starts with "https://www.youtube.com/watch" then
execute javascript "
var player = document.getElementById('movie_player') || document.getElementsByTagName('embed')[0];
if (player) {
document.getElementsByClassName('ytp-prev-button')[0].click()
}
"
exit repeat
end if
end tell
end repeat
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment