Created
September 24, 2021 03:25
-
-
Save directmusic/4e135eda438cba100174206ed4f3c73b to your computer and use it in GitHub Desktop.
Ableton Live Hammerspoon - Close plugin window with CMD-W
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
live_hotkey = hs.hotkey.bind({"cmd"}, "W", function() | |
local win = hs.window.focusedWindow() | |
if win:application():name() == "Live" then -- Check if window belongs to Live | |
if string.find(win:title(), "/") then -- Plugin windows in Live have "/" in the title. The main window does not. | |
win:close(); | |
end | |
else | |
live_hotkey:disable(); -- we have to disable the hotkey to send CMD-W through | |
hs.eventtap.event.newKeyEvent(hs.keycodes.map.cmd, true):post() | |
hs.eventtap.event.newKeyEvent("w", true):post() | |
hs.eventtap.event.newKeyEvent("w", false):post() | |
hs.eventtap.event.newKeyEvent(hs.keycodes.map.cmd, false):post() | |
live_hotkey:enable(); -- enable the hotkey once again | |
end | |
end) | |
live_hotkey:enable(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pretty fun! thanks for posting. What I'm wondering is, what other Hammerspoon things have you been working on @directmusic , and if you've found a way to automatically focus the plugin window? Currently I need to click on the plugin-window, for CMD-W to work.