I created this AppleScript to play/pause Youtube videos running on Chrome:
on run {input, parameters}
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('ytp-play-button ytp-button')[0].click();"
end tell
return input
end run
It works fine when I run it from Automator
. I saved the service and added a keyboard shortcut ⌘+J
for running the service. I also added Automator
to the Accessibility
settings (following this SO answer).
Now here's the strange part: it works when I have the System Preferences
window on focus. If I close it, or switch to any other window, the shortcut doesn't work. I noticed that it's working because there's a menu item in System Preferences
window that corresponds to the shortcut, and that is getting triggered when I press the shortcut.
Please help. Thanks in advance.
Preview, Script Editor, Mail, TextEdit, iTunes, Safari, Finder, Terminal, Microsoft Word, TextWrangler, Automator
, etc..)