A window filter picks out some of the windows on your Mac with a set of rules, such as "visible
windows in the current Space, except Finder's". You can ask a filter for the windows it allows
right now, or listen for events about them: windows being created, focused, moved, minimized,
joining or leaving the filter, and so on.
// Every visible window of every app, except a few utility apps constwf = hs.windowfilter.defaultFilter
// Only Safari and Mail's visible windows constmailAndWeb = hs.windowfilter.create(["Safari", "Mail"])
// Visible, non-fullscreen windows in the current Space; no windows at all from Finder, and // only titled windows from Terminal constcustom = hs.windowfilter.create({ override: { currentSpace:true, fullscreen:false }, default: { visible:true }, apps: { Finder:false, "com.apple.Terminal": { visible:true, allowTitles:1 } }, })
A window must pass the override rule, if there is one. Then the rule for its application
decides, or the default rule if the application has none of its own. An application rule
replaces the default rule rather than adding to it.
A rule is true (the application's visible windows), false (none of them), or an object of
conditions, all of which must hold:
visible: true for only visible windows (neither minimized nor hidden), false for only
invisible ones
currentSpace: true for only windows in a Space currently shown, false for only
windows in other Spaces. Minimized and hidden windows count as being in every Space.
fullscreen, focused, hasTitlebar: true to require the window to be fullscreen,
focused, or to have a titlebar; false to require it not to be
activeApplication: true for only windows of the active application, false for only
other applications' windows
allowTitles: a number, for windows whose titles are at least that many characters long
(so 1 rejects untitled windows); or a string (an exact title), a RegExp, or an array of
them, for windows whose titles match one
rejectTitles: a string, RegExp, or array of them; windows whose titles match one are rejected
allowRegions, rejectRegions: an HSRect (or {x, y, w, h}), or an array of them.
A window is in a region if at least half of it is inside, or it covers at least half of the
region.
allowScreens, rejectScreens: an HSScreen, a screen's name or UUID, or an array of
them, for the screen holding most of the window
allowRoles: a window subrole (see HSWindow.subrole), an array of them, or "*" for any
window. Defaults to hs.windowfilter.allowedWindowRoles, except in the override rule,
which allows any subrole unless it says otherwise. macOS reports minimized windows, and
every window of a hidden application, as "AXDialog", so these rules see the subrole a
window had when it was last shown instead. A window that has only been seen minimized or
hidden counts as an "AXStandardWindow" if it can be minimized, as dialogs can't (see
HSWindow.isStandard). One that can't be minimized, such as TextEdit's Settings window
first seen while TextEdit is hidden, counts as an "AXDialog" until it's shown.
Regions and screens only apply to visible windows. RegExps support the i, m and s flags.
Hammerspoon's own windows (such as the Console) are included like any other application's.
An hs.canvas reports a subrole ending in .Hammerspoon (see
HSCanvas.setAccessibilitySubrole), which the default roles don't include, so only a rule
that allows its subrole sees it.
Applications that turn Accessibility off
Window filters see windows through the Accessibility API, which an application can turn off
for itself (Firefox does in kiosk mode). Such an application's windows never appear in any
filter. hs.windowfilter.inaccessibleApplications() lists them, and the module's
inaccessibleApplication event reports each one as it's found, so you can still offer them
some other way, e.g. by activating the application.
Window filters
A window filter picks out some of the windows on your Mac with a set of rules, such as "visible windows in the current Space, except Finder's". You can ask a filter for the windows it allows right now, or listen for events about them: windows being created, focused, moved, minimized, joining or leaving the filter, and so on.
Rules
A window must pass the
overriderule, if there is one. Then the rule for its application decides, or thedefaultrule if the application has none of its own. An application rule replaces the default rule rather than adding to it.A rule is
true(the application's visible windows),false(none of them), or an object of conditions, all of which must hold:visible:truefor only visible windows (neither minimized nor hidden),falsefor only invisible onescurrentSpace:truefor only windows in a Space currently shown,falsefor only windows in other Spaces. Minimized and hidden windows count as being in every Space.fullscreen,focused,hasTitlebar:trueto require the window to be fullscreen, focused, or to have a titlebar;falseto require it not to beactiveApplication:truefor only windows of the active application,falsefor only other applications' windowsallowTitles: a number, for windows whose titles are at least that many characters long (so1rejects untitled windows); or a string (an exact title), a RegExp, or an array of them, for windows whose titles match onerejectTitles: a string, RegExp, or array of them; windows whose titles match one are rejectedallowRegions,rejectRegions: anHSRect(or{x, y, w, h}), or an array of them. A window is in a region if at least half of it is inside, or it covers at least half of the region.allowScreens,rejectScreens: anHSScreen, a screen's name or UUID, or an array of them, for the screen holding most of the windowallowRoles: a window subrole (seeHSWindow.subrole), an array of them, or"*"for any window. Defaults tohs.windowfilter.allowedWindowRoles, except in the override rule, which allows any subrole unless it says otherwise. macOS reports minimized windows, and every window of a hidden application, as"AXDialog", so these rules see the subrole a window had when it was last shown instead. A window that has only been seen minimized or hidden counts as an"AXStandardWindow"if it can be minimized, as dialogs can't (seeHSWindow.isStandard). One that can't be minimized, such as TextEdit's Settings window first seen while TextEdit is hidden, counts as an"AXDialog"until it's shown.Regions and screens only apply to visible windows. RegExps support the
i,mandsflags.Hammerspoon's own windows (such as the Console) are included like any other application's. An
hs.canvasreports a subrole ending in.Hammerspoon(seeHSCanvas.setAccessibilitySubrole), which the default roles don't include, so only a rule that allows its subrole sees it.Applications that turn Accessibility off
Window filters see windows through the Accessibility API, which an application can turn off for itself (Firefox does in kiosk mode). Such an application's windows never appear in any filter.
hs.windowfilter.inaccessibleApplications()lists them, and the module'sinaccessibleApplicationevent reports each one as it's found, so you can still offer them some other way, e.g. by activating the application.