aboutsummaryrefslogtreecommitdiffstats
path: root/application_switch.lua
blob: 8835fe5916e33b62104839bf942b2e96e1d42b3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
-- Copyright (c) 2019  Teddy Wing
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <https://www.gnu.org/licenses/>.


local activateAllWindows = true

application_switch = {}

application_switch['f1'] = hs.hotkey.bind({}, 'f1', function()
	hs.application.find('com.apple.Terminal'):activate()
end)

application_switch['f2'] = hs.hotkey.bind({}, 'f2', function()
	hs.application.find('org.mozilla.nightly'):activate(activateAllWindows)
end)

application_switch['f3'] = hs.hotkey.bind({}, 'f3', function()
	hs.application.find('com.google.Chrome'):activate(activateAllWindows)
end)

application_switch['f4'] = hs.hotkey.bind({}, 'f4', function()
	hs.application.find('com.microsoft.rdc.osx.beta'):activate()
end)

application_switch['f5'] = hs.hotkey.bind({}, 'f5', function()
	hs.application.find('com.googlecode.iterm2'):activate(activateAllWindows)
end)


-- Rebind Shift-F[n] to F[n]
for _, key in ipairs({'f1', 'f2', 'f3', 'f4', 'f5'}) 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()
	application_switch_mode:exit()
end)

application_switch_mode:bind({}, 'escape', function()
	application_switch_mode:exit()
end)

application_switch_mode:bind({}, 'q', function()
	hs.application.find('org.libreoffice.script'):activate(activateAllWindows)

	application_switch_mode:exit()
end)

application_switch_mode:bind({}, 'w', function()
	hs.application.find('com.microsoft.Word'):activate(activateAllWindows)

	application_switch_mode:exit()
end)

application_switch_mode:bind({}, 'e', function()
	hs.application.find('com.apple.TextEdit'):activate(activateAllWindows)

	application_switch_mode:exit()
end)

application_switch_mode:bind({}, 'x', function()
	hs.application.find('com.microsoft.Excel'):activate(activateAllWindows)

	application_switch_mode:exit()
end)

application_switch_mode:bind({}, 'f', function()
	hs.application.find('com.googlecode.iterm2'):activate(activateAllWindows)

	application_switch_mode:exit()
end)

application_switch_mode:bind({}, 'v', function()
	hs.application.find('com.apple.Preview'):activate(activateAllWindows)

	application_switch_mode:exit()
end)