Thanks for HarsilSPatel for inspiring my solution. In my case I wanted to re-arrange certain apps into specific screens.
For example when coming home from the office, the screens in the OS are different, and the apps would open in different screens when you go back and forth.
hs.application.enableSpotlightForNameSearches(true) function rearrangeWindows() return function() local screens = hs.screen.allScreens() local leftScreen = screens[2] local rightScreen = screens[3] local mainScreen = screens[1] -- Left moveWindowToScreen("Warp", leftScreen, true) -- Main moveWindowToScreen("Finder", mainScreen, false) moveWindowToScreen("Visual Studio Code", mainScreen, false) -- Right moveWindowToScreen("Chrome", rightScreen, true) moveWindowToScreen("Notion", rightScreen, true) hs.alert.show("Rearranged apps", {}, hs.screen.primaryScreen()) end end function moveWindowToScreen(app, screen, maximize) local win = hs.application.find(app) if win == nil then return end -- print("Found window for " .. app) local mainWindow = win:mainWindow() if mainWindow == nil then return end -- print("Moving " .. app .. " to " .. screen:name()) mainWindow:moveToScreen(screen, true, true, 0) if maximize then mainWindow:maximize(0) end end hs.hotkey.bind({"alt", "cmd"}, "pad0", rearrangeWindows())