Skip to content

Instantly share code, notes, and snippets.

@ryan6416
Last active July 19, 2022 01:47
Show Gist options
  • Save ryan6416/01d58d53633065b77227647f39c5a54d to your computer and use it in GitHub Desktop.
Save ryan6416/01d58d53633065b77227647f39c5a54d to your computer and use it in GitHub Desktop.
applescript_youtube_music_control_for_chrome
on run argv
tell application "Google Chrome"
set allWins to every window
set allTabs to {}
repeat with currWin in allWins
set allTabs to allTabs & every tab of currWin
end repeat
repeat with currTab in allTabs
try
if (title of currTab) contains "Youtube Music" then set musicTab to currTab
end try
end repeat
tell musicTab to execute javascript "(document.querySelector('[aria-label=\"Next song\"]')).click();"
end tell
end run
on run argv
tell application "Google Chrome"
set allWins to every window
set allTabs to {}
repeat with currWin in allWins
set allTabs to allTabs & every tab of currWin
end repeat
repeat with currTab in allTabs
try
if (title of currTab) contains "Youtube Music" then set musicTab to currTab
end try
end repeat
tell musicTab to execute javascript "(document.querySelector('[id=\"play-pause-button\"]')).click();"
end tell
end run
on run argv
tell application "Google Chrome"
set allWins to every window
set allTabs to {}
repeat with currWin in allWins
set allTabs to allTabs & every tab of currWin
end repeat
repeat with currTab in allTabs
try
if (title of currTab) contains "Youtube Music" then set musicTab to currTab
end try
end repeat
tell musicTab to execute javascript "(document.querySelector('[aria-label=\"Previous song\"]')).click();"
end tell
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment