1

My current code for switching to a desired app is this:

hs.hotkey.bindSpec( { hyper , "k"},
  function()
    hs.application.launchOrFocus("Visual Studio Code")
  end
)

But I have opened multiple windows of VSCode.

And I would like to have it integrated into this shortcut so it does the alt + ` shortcut and rotate between all available VSCode windows as I press hyper key + k.

Any idea how to change my code that it works like that?

1 Answer 1

0

Met the same problem, and here is my final result:

-- launch, focus or rotate application
local function launchOrFocusOrRotate(app)
    local focusedWindow = hs.window.focusedWindow()
    -- If already focused, try to find the next window
    if focusedWindow and focusedWindow:application():name() == app then
        local appWindows = hs.application.get(app):allWindows()
        if #appWindows > 0 then
            -- It seems that this list order changes after one window get focused, 
            -- let's directly bring the last one to focus every time
            appWindows[#appWindows]:focus()
        else -- this should not happen, but just in case
            hs.application.launchOrFocus(app)
        end
    else -- if not focused
        hs.application.launchOrFocus(app)
    end
end

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .