Skip to content

Instantly share code, notes, and snippets.

@tamastimar
Last active April 12, 2021 12:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamastimar/3fc39cf983ad3187ed2e to your computer and use it in GitHub Desktop.
Save tamastimar/3fc39cf983ad3187ed2e to your computer and use it in GitHub Desktop.
Hammerspoon (http://hammerspoon.org) script to switch to next window of frontmost app in OS X
-- Window Manipulation
-- Bind alt-Tab to show next window of current application
hs.hotkey.bind({"alt"}, "Tab", function()
local app = hs.application.frontmostApplication()
local windows = app:allWindows()
local nextWin = nil
-- Finder somehow has one more invisible window, so don't take it into account
-- (only tested on Yosemite 10.10.1)
if app:bundleID() == "com.apple.finder" then
nextWin = windows[#windows-1]
else
nextWin = windows[#windows]
end
if nextWin:isMinimized() == true then
nextWin:unminimize()
else
nextWin:focus()
end
end)
@cmsj
Copy link

cmsj commented Feb 18, 2015

I haven't checked to be sure, but I am tempted to guess that Finder's weird invisible window might well be the desktop

@tamastimar
Copy link
Author

Thanks for the comment!

Even if that's the case unfortunately it doesn't respond to the focus() call. (Maybe that's how the desktop should work.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment