Skip to content

Instantly share code, notes, and snippets.

@ShiningRay
Created April 7, 2017 09:16
Show Gist options
  • Save ShiningRay/c54a638378a1c26c5e13429480504528 to your computer and use it in GitHub Desktop.
Save ShiningRay/c54a638378a1c26c5e13429480504528 to your computer and use it in GitHub Desktop.
automaticly focus the frontmost window when mouse changed to another screen
-- hs.logger.setGlobalLogLevel('debug')
local logger = hs.logger.new('focus')
hs.timer.doEvery(3, function()
local current = hs.mouse.getCurrentScreen()
-- hs.rawprint(current)
if current and current ~= hs.screen.mainScreen() then
local windows = hs.window.orderedWindows()
for _, l in ipairs(windows) do
if l:screen() == current and l:isStandard() and l:isVisible() then
logger.i('mouse changed to ' .. current:name() .. ', focus ' .. l:title())
l:focus()
break
end
end
end
end):start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment