You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! I was going to build a little Spoon that allows me to close windows. ChatGPT gave me
Code
-- Function to get a list of visible windows for user applicationsfunctiongetVisibleWindows()
localwindows= {}
localallWindows=hs.window.allWindows()
for_, windowinipairs(allWindows) doifwindow:application():kind() ==1andwindow:isVisible() then-- Only list windows of user applications that are visibletable.insert(windows, {text=window:title(), windowObj=window})
endendreturnwindowsend-- Function to close the windowfunctioncloseWindow(window)
ifwindowthenwindow:close()
endend-- Function to quit the application of the windowfunctionquitAppOfWindow(window)
ifwindowthenwindow:application():kill()
endend-- Create the chooserwindowChooser=hs.chooser.new(function(choice)
ifnotchoicethenreturnend-- Placeholder for action, actual action is handled in keydown eventend)
-- Set the choiceswindowChooser:choices(getVisibleWindows)
-- Handle keydown event for the chooserwindowChooser:keydown(function(chooser, event)
localchoice=chooser:selectedRowContents()
ifevent:getCharacters() =="w" andevent:getFlags().cmdthencloseWindow(choice.windowObj)
chooser:refreshChoicesCallback() -- Refresh the list of windowselseifevent:getCharacters() =="q" andevent:getFlags().cmdthenquitAppOfWindow(choice.windowObj)
chooser:refreshChoicesCallback() -- Refresh the list of windowsendend)
-- Show the window chooserhs.hotkey.bind({"cmd"}, "E", function() windowChooser:show() end)
I was surprised that hs.chooser does not allow you to act on key down presses (:keydown in the code). Could this be added to hs.chooser?
The text was updated successfully, but these errors were encountered:
Hi! I was going to build a little Spoon that allows me to close windows. ChatGPT gave me
Code
I was surprised that
hs.chooser
does not allow you to act on key down presses (:keydown
in the code). Could this be added to hs.chooser?The text was updated successfully, but these errors were encountered: