Skip to content

Instantly share code, notes, and snippets.

@directmusic
Created September 24, 2021 03:25
Show Gist options
  • Save directmusic/4e135eda438cba100174206ed4f3c73b to your computer and use it in GitHub Desktop.
Save directmusic/4e135eda438cba100174206ed4f3c73b to your computer and use it in GitHub Desktop.
Ableton Live Hammerspoon - Close plugin window with CMD-W
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();
@esaruoho
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment