Skip to content

Instantly share code, notes, and snippets.

@dmgerman
Created January 6, 2026 15:56
Show Gist options
  • Select an option

  • Save dmgerman/efb6bf40e9dc106700a41cb70edb95dd to your computer and use it in GitHub Desktop.

Select an option

Save dmgerman/efb6bf40e9dc106700a41cb70edb95dd to your computer and use it in GitHub Desktop.
windowKeys = {}
function wkeys_prompt_for_key()
local w = hs.window.focusedWindow()
local result = nil
hs.application.get("Hammerspoon"):activate()
local button, text = hs.dialog.textPrompt("Input number key", "Please enter a single numeric character:", "", "OK", "Cancel")
if button == "OK" then
result = text
end
if w then
w:focus()
end
return result
end
function wkeys_attach_current_window_to_key()
local w = hs.window.focusedWindow()
if (w) then
local key = wkeys_prompt_for_key()
if key and tonumber(key) then
print(string.format("key [%s]", key))
dmg_alert(string.format("attach key [%s] to window [%s]", key, w:title()))
hs.hotkey.bind(
{'alt'}, key,
function () w:focus() end)
else
dmg_alert(string.format("Illegal key to attach a window [%s]", key))
end
end
end
hs.hotkey.bind(
{'alt'}, '0',
function () wkeys_attach_current_window_to_key() end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment