1

While switching windows with keyboard on MacOS, the default CMD+TAB command shows all the active windows. I use hammerspoon to switch only between windows on a single desktop.

This is the script I use for achieving that.

local wf = hs.window.filter filter = wf.new():setCurrentSpace(true):setDefaultFilter{} switcher_space = hs.window.switcher.new(filter) hs.window.switcher.ui.showThumbnails = false hs.window.switcher.ui.showSelectedThumbnail = false hs.hotkey.bind('alt', 'tab', 'Next window', function() switcher_space:next() hs.alert.closeAll() end) hs.hotkey.bind('alt-shift', 'tab', 'Prev window', function() switcher_space:previous() hs.alert.closeAll() end) 

Similar to what we have in the documentation.

This is working fine for a single monitor. But when I connect one more monitor the switcher_space has windows on the active desktop with the windows on desktop on the other monitor. I would like to see only the windows from the active monitor (currently focused).

While reading the documentation I found that I have to use setScreens method on window filter. But using it like this

screen_id = hs.screen.primaryScreen():id() filter = wf.new():setScreens(screen_id):setCurrentSpace(true):setDefaultFilter{} 

throws

invalid key in filter table: _allowedScreens 

1 Answer 1

0

This config solves the problem

local wf = hs.window.filter -- print primary screen id screen_id = hs.screen.primaryScreen():id() print(screen_id) filter = wf.new():setCurrentSpace(true):setDefaultFilter{}:setScreens(screen_id) switcher_space = hs.window.switcher.new(filter) hs.window.switcher.ui.showThumbnails = false hs.window.switcher.ui.showSelectedThumbnail = false hs.hotkey.bind('alt', 'tab', 'Next window', function() switcher_space:next() hs.alert.closeAll() end) hs.hotkey.bind('alt-shift', 'tab', 'Prev window', function() switcher_space:previous() hs.alert.closeAll() end) -- Bind option + number keys to switch spaces for i = 1, 6 do hs.hotkey.bind('alt', tostring(i), function() hs.spaces.gotoSpace(i+2) end) end print(hs.spaces.allSpaces()) 
Sign up to request clarification or add additional context in comments.

1 Comment

How does this address the issue? Please edit your answer and explain the changes you've made to solve the problem. Code-only answers are not good answers.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.