Correct way to detect whether the Console is open? #3079
-
Anyone know the "correct" way to tell if the Hammerspoon Console is open? The best I could come up with is this: function isConsoleOpen()
return hs.console.hswindow() ~= nil
end |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Any way that works is correct -- there is often more than one way to do something in Hammerspoon. That said, I've found that some methods can sometimes seem to lag... I've found that the following seems to avoid the lag most (all? haven't seen it in a while) of the time: function isConsoleOpen()
local hspoon = hs.application.applicationsForBundleID(hs.processInfo.bundleID)[1]
local conswin = hspoon:mainWindow()
return conswin and true or false
end FWIW, I use this in the following hot key which toggles to console for me -- if it's closed, open the console; if it's open but not frontmost, make it frontmost; if it's open and frontmost, close it -- it also tries to remember the window that was frontmost prior to bringing up the console so I go back to it when I toggle the console out. local windowHolder
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "r", function()
local hspoon = hs.application.applicationsForBundleID(hs.processInfo.bundleID)[1]
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 = window.frontmostWindow()
hs.openConsole()
end
end, nil) |
Beta Was this translation helpful? Give feedback.
Any way that works is correct -- there is often more than one way to do something in Hammerspoon.
That said, I've found that some methods can sometimes seem to lag... I've found that the following seems to avoid the lag most (all? haven't seen it in a while) of the time:
FWIW, I use this in the following hot key which toggles to console for me -- if it's closed, open the console; if it's open but not frontmost, make it frontmost; if it's open and frontmost, close it -- it also tries to remember the window …