Skip to content

Correct way to detect whether the Console is open? #3079

Answered by asmagill
luckman212 asked this question in Q&A
Discussion options

You must be logged in to vote

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 …

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@luckman212
Comment options

@Rhys-T
Comment options

@unphased
Comment options

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