From 2e53f7c779f1f84d047eb32321d9bbd4a8403c50 Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Mon, 25 Apr 2022 10:42:01 -0400 Subject: [PATCH] add macos window moving --- .../Spoons/MoveWindow.spoon/init.lua | 24 +++++++++++++++++++ hammerspoon.symlink/init.lua | 1 + 2 files changed, 25 insertions(+) create mode 100644 hammerspoon.symlink/Spoons/MoveWindow.spoon/init.lua diff --git a/hammerspoon.symlink/Spoons/MoveWindow.spoon/init.lua b/hammerspoon.symlink/Spoons/MoveWindow.spoon/init.lua new file mode 100644 index 0000000..dc6071c --- /dev/null +++ b/hammerspoon.symlink/Spoons/MoveWindow.spoon/init.lua @@ -0,0 +1,24 @@ +--- === Move Window === + +local obj = {} +obj.__index = obj + +-- Metadata +obj.name = "MoveWindow" +obj.version = "0.1" +obj.license = "MIT - https://opensource.org/licenses/MIT" + +function obj:init() + -- bind hotkey + hs.hotkey.bind({ "alt", "ctrl", "cmd" }, "n", function() + -- get the focused window + local win = hs.window.focusedWindow() + -- get the screen where the focused window is displayed, a.k.a. current screen + local screen = win:screen() + -- compute the unitRect of the focused window relative to the current screen + -- and move the window to the next screen setting the same unitRect + win:move(win:frame():toUnitRect(screen:frame()), screen:next(), true, 0) + end) +end + +return obj diff --git a/hammerspoon.symlink/init.lua b/hammerspoon.symlink/init.lua index 8e4dcfe..b4a3dc1 100644 --- a/hammerspoon.symlink/init.lua +++ b/hammerspoon.symlink/init.lua @@ -1,3 +1,4 @@ hs.loadSpoon("ControlEscape"):start() -- Load Hammerspoon bits from https://github.com/jasonrudolph/ControlEscape.spoon hs.loadSpoon("Launcher"):init() hs.loadSpoon("DismissAlerts"):init() +hs.loadSpoon("MoveWindow"):init()