aboutsummaryrefslogtreecommitdiffstats
path: root/application_switch.lua
diff options
context:
space:
mode:
authorTeddy Wing2019-06-20 00:53:30 +0200
committerTeddy Wing2019-06-20 00:53:30 +0200
commit46123783335aab2f40c89b684d5add8d2618cb7d (patch)
treed16b3381d8db7f49195d0ef8c7000a40a073ef75 /application_switch.lua
parent2e5cc43d7d25295a14d634b53af48a6449cd909f (diff)
downloaddothammerspoon-46123783335aab2f40c89b684d5add8d2618cb7d.tar.bz2
application_switch: Provide access to F1–F4 keys
Since I overrode the F1 through F4 keys globally, there was no way to access press a non-custom variant of these keys. Realised this when trying to access the manual in Mutt, which is bound to F1. Add Shift-F1–F4 bindings that map to F1–F4, in case we need access to the original set of keys. Needed to add a `doAfter` delay after disabling the binding because the delay seems to take a bit to go through. Thanks to 'knu' (https://github.com/knu) for the tip: https://github.com/Hammerspoon/hammerspoon/issues/1252#issuecomment-290411701 Also gleaned it from: https://stackoverflow.com/questions/40986242/key-repeats-are-delayed-in-my-hammerspoon-script
Diffstat (limited to 'application_switch.lua')
-rw-r--r--application_switch.lua24
1 files changed, 20 insertions, 4 deletions
diff --git a/application_switch.lua b/application_switch.lua
index 84dbe88..988a2b6 100644
--- a/application_switch.lua
+++ b/application_switch.lua
@@ -1,21 +1,37 @@
local activateAllWindows = true
-hs.hotkey.bind({}, 'f1', function()
+application_switch = {}
+
+application_switch['f1'] = hs.hotkey.bind({}, 'f1', function()
hs.application.find('com.apple.Terminal'):activate()
end)
-hs.hotkey.bind({}, 'f2', function()
+application_switch['f2'] = hs.hotkey.bind({}, 'f2', function()
hs.application.find('org.mozilla.nightly'):activate(activateAllWindows)
end)
-hs.hotkey.bind({}, 'f3', function()
+application_switch['f3'] = hs.hotkey.bind({}, 'f3', function()
hs.application.find('com.google.Chrome'):activate(activateAllWindows)
end)
-hs.hotkey.bind({}, 'f4', function()
+application_switch['f4'] = hs.hotkey.bind({}, 'f4', function()
hs.application.find('com.microsoft.rdc.osx.beta'):activate()
end)
+-- Rebind Shift-F[n] to F[n]
+for _, key in ipairs({'f1', 'f2', 'f3', 'f4'}) do
+ hs.hotkey.bind({'shift'}, key, function()
+ application_switch[key]:disable()
+
+ hs.timer.doAfter(0.05, function()
+ hs.eventtap.keyStroke({}, key)
+
+ application_switch[key]:enable()
+ end)
+ end)
+end
+
+
-- Mode to activate lesser-used applications
application_switch_mode = hs.hotkey.modal.new({}, 'f13')
application_switch_mode:bind({}, 'f13', function()