Skip to content

Resilient auto config loading #3673

Answered by unphased
unphased asked this question in Q&A
Aug 16, 2024 · 2 comments · 6 replies
Discussion options

You must be logged in to vote

Code is now:

-- Toggle Hammerspoon console. records focused window on open, so may return to the wrong window upon using it to close.
local windowHolder
hs.hotkey.bind("Ctrl-Cmd", "H", function()
    local hspoon = hs.application(hs.processInfo.processID)
    local conswin = hspoon:mainWindow()
    if conswin and hspoon:isFrontmost() then
        conswin:close()
        if windowHolder and #windowHolder:role() ~= 0 then
            windowHolder:becomeMain():focus()
        end
        windowHolder = nil
    else
        windowHolder = hs.window.frontmostWindow()
        hs.openConsole()
    end
end)

local home = os.getenv("HOME")
-- watcher object must be assigned to global not to get GC'd

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
6 replies
@unphased
Comment options

@asmagill
Comment options

@unphased
Comment options

@unphased
Comment options

Answer selected by unphased
@unphased
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants