Skip to content

Instantly share code, notes, and snippets.

@jQwotos
Created January 18, 2021 07:48
Show Gist options
  • Save jQwotos/7c7656a1ff48a47ae02106e78de4f808 to your computer and use it in GitHub Desktop.
Save jQwotos/7c7656a1ff48a47ae02106e78de4f808 to your computer and use it in GitHub Desktop.
Spoon for Hamerspoon that moves Windows between Physical Screens
local obj = {}
obj.__index = obj
-- Heavily inspired by suggestion on stack overflow by Karsten S. (2019)
-- https://stackoverflow.com/questions/54151343/how-to-move-an-application-between-monitors-in-hammerspoon
obj.name = "MoveScreens"
obj.version = "1.0"
obj.author = "Jason L."
obj.license = ""
obj.logger = hs.logger.new("MoveScreens", "debug")
obj.speed = 0
-- Adjust speed to change how fast this moves
obj.mash = { 'ctrl', 'alt', 'cmd' }
obj.mapping = {
first = { obj.mash, '1' },
second = { obj.mash, '2' }
}
function obj:moveWindowToDisplay(d)
return function()
local displays = hs.screen.allScreens()
local win = hs.window.focusedWindow()
self.logger.i('Moving ', win, ' to display ', d)
win:moveToScreen(displays[d], false, true, self.speed)
end
end
function obj:init()
hs.hotkey.bind(self.mapping.first[1], self.mapping.first[2], self:moveWindowToDisplay(1))
hs.hotkey.bind(self.mapping.second[1], self.mapping.second[2], self:moveWindowToDisplay(2))
return self
end
return obj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment