I would like to control media in Google Chrome using shortcuts, more specifically I would like to be able to fast forward/rewind 3 seconds using a keyboard shortcut that works globally no matter what app is in front. I'm using Mac which lets me control start/stop globally with a hotkey but I have been unable to find a solution for fast forward/rewind.
To be even more specific. I would like to be able to rewind YouTube videos and udemy videos using just a hotkey while I'm working in an IDE. So let's say I'm writing in an IDE while listening to a video about programming running on udemy, at this point I can use a hotkey to pause and start the video even though I am working in the IDE. But I would also like to rewind 3 seconds with just a hotkey if there was something I need to hear again, but I don't want to have to manually switch to the browser and then use a hotkey to rewind the video.
I want to do be able to do it with just one action.
Here's an example with YouTube. It brings the browser (in my case, Brave) to the front, rewinds by simulating the โ key, and then brings the app you started in back to the front.
Thanks for the quick reply. For some reason it didn't work for me when I tried using it in chrome, however I made another version that does the same thing just using cmnd+tab and it worked fine on both udemy and youtube.
However both these solutions are a bit flimsy and there are situations where they wont work, like if you have a second browser window open it will sometimes mess up the macro.
Okay let's go a bit deeper. Change the name of the media-playing website in the green action and change the red actions according to your browser of choice. Three of the four red actions just require you to choose a different browser from the drop-down; in the AppleScript, you'll want to change:
tell application "Brave Browser"
to, for example tell application "Google Chrome"
Of course, if you have multiple YouTube tabs, this may not work as expected. We could have a go at identifying the tab that's currently playing media... but for now, let's see if this works for you in principle.
With reference to multiple tabs whose titles include the same name... If you're using a Chrome-based browser, we might be able to incorporate this into the macro:
I don't use a macro to do this, but another app called Movist Pro. It does exactly what you want; control a video, YouTube or otherwise, in the background, using the built-in media keys to fast forward and rewind. You can even customize the seek speed.
--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2022/11/18 21:33
# dMod: 2022/11/19 00:12
# Appl: Google Chrome, System Events
# Task: Bring a Singular YouTube Window to the Front.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Google_Chrome, @System_Events, @YouTube, @Window, @Front
--------------------------------------------------------
set theURL to "https://www.youtube.com/"
tell application "Google Chrome"
set winList to windows whose active tab's URL is theURL
if length of winList = 1 then
set youtubeWindow to item 1 of winList
if index of youtubeWindow โ 1 then
set index of youtubeWindow to 1
raiseWindow() of me
end if
else
beep
error "Too many or too few windows were found!"
end if
end tell
--------------------------------------------------------
--ยป HANDLERS
--------------------------------------------------------
on raiseWindow()
tell application "System Events"
tell (first application process whose frontmost is true)
tell front window
perform action "AXRaise"
end tell
end tell
end tell
end raiseWindow
--------------------------------------------------------
Some improvements I can imagine to my macro suggestion above are:
Make tab with desired URL frontmost without needing to switch to the browser, so keystrokes can be sent to it discreetly. Is that what your script does, @ccstone? I haven't had a chance to try it yet.
Make tab currently playing audio the frontmost tab, rather than set by URL, in case there are multiple tabs off the same URL family.