Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

yustas

macrumors 6502a
Original poster
Dec 11, 2009
553
464
If I watch YouTube on a MacBook with an external monitor and have another window opened on an external monitor, the focus switches to the window I last clicked on. So if I'm coding on an external monitor and want to quickly rewind the YouTube video on the MacBook with left/right keys on the keyboard, I have to mouse over back to the Youtube video to do that, because the focus is on the external monitor's window.

Is there any way around this?
 
How else is the Mac supposed to know if the arrow keys should be directed to Safari/YouTube or to your code editor? You either have to click that screen/app to give it focus again, or use a keyboard shortcut to switch to that app to give it focus (i.e. Command-Tab).

Another way to control the video is by using 'Now Playing' control that shows up in the menu bar to scrub, replay, skip ahead, or play/pause.

1736972723019.png


If you have media keys on your keyboard, they'll work at all times (YouTube does not need focus), but YouTube has the prev/next keys set to go to the prev/next video in a playlist. I don't think you can change the behavior of that.

 
You can use the below Hammerspoon script to automatically change focus whenever your mouse moves between monitors. It won't solve your keyboard issue, but it will remove the need to perform an extra click to change focus to the other monitor.

-- Keep track of the current screen
local lastScreen = hs.mouse.getCurrentScreen()

-- Function to focus a window on the new screen
local function focusScreenUnderMouse()
local currentScreen = hs.mouse.getCurrentScreen()

if currentScreen ~= lastScreen then
lastScreen = currentScreen
local windows = hs.window.orderedWindows()

for _, win in ipairs(windows) do
if win:screen() == currentScreen and win:isStandard() then
win:focus()
break
end
end
end
end

-- Watch mouse position changes
mouseWatcher = hs.eventtap.new({ hs.eventtap.event.types.mouseMoved }, function(e)
focusScreenUnderMouse()
return false
end)

mouseWatcher:start()
 
Last edited:
  • Like
Reactions: foliovision
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.