2021-08-30 15:36:04 -06:00
|
|
|
--- === Launcher ===
|
|
|
|
|
2021-12-27 22:31:30 -07:00
|
|
|
local obj = {}
|
2021-08-30 15:36:04 -06:00
|
|
|
obj.__index = obj
|
|
|
|
|
|
|
|
-- Metadata
|
2021-12-27 22:31:30 -07:00
|
|
|
obj.name = "Launcher"
|
|
|
|
obj.version = "0.1"
|
|
|
|
obj.license = "MIT - https://opensource.org/licenses/MIT"
|
2021-08-30 15:36:04 -06:00
|
|
|
|
2023-03-08 10:30:25 -05:00
|
|
|
local width = hs.screen.mainScreen():fullFrame().w
|
|
|
|
local switcherWidth = 500
|
|
|
|
obj.canvas = hs.canvas.new({
|
|
|
|
x = width / 2 - switcherWidth / 2,
|
|
|
|
y = 1,
|
|
|
|
h = 3,
|
|
|
|
w = switcherWidth,
|
|
|
|
})
|
|
|
|
-- Draw switcher
|
|
|
|
obj.canvas[#obj.canvas + 1] = {
|
|
|
|
action = "build",
|
|
|
|
type = "rectangle",
|
|
|
|
}
|
|
|
|
obj.canvas[#obj.canvas + 1] = {
|
|
|
|
type = "rectangle",
|
|
|
|
fillColor = { alpha = 1, red = 0.8, green = 0.6, blue = 0.3 },
|
|
|
|
action = "fill",
|
|
|
|
}
|
2022-04-16 16:50:03 -04:00
|
|
|
|
2021-08-30 15:36:04 -06:00
|
|
|
function obj:init()
|
2022-04-16 16:50:03 -04:00
|
|
|
-- Begin launcher mode
|
2022-04-21 14:22:02 -04:00
|
|
|
if self.launcher == nil then
|
|
|
|
self.launcher = hs.hotkey.modal.new("ctrl", "space")
|
2023-03-08 10:30:25 -05:00
|
|
|
|
|
|
|
print(self.canvas)
|
|
|
|
print(obj.canvas)
|
2022-04-21 14:22:02 -04:00
|
|
|
end
|
2021-08-30 15:36:04 -06:00
|
|
|
|
2022-04-16 16:50:03 -04:00
|
|
|
-- Behaviors on enter
|
|
|
|
function self.launcher:entered()
|
|
|
|
-- hs.alert("Entered mode")
|
2023-03-08 10:30:25 -05:00
|
|
|
obj.canvas:show()
|
2022-04-16 16:50:03 -04:00
|
|
|
end
|
2022-08-14 20:44:18 -06:00
|
|
|
|
2022-04-16 16:50:03 -04:00
|
|
|
-- Behaviors on exit
|
|
|
|
function self.launcher:exited()
|
|
|
|
-- hs.alert("Exited mode")
|
2023-03-08 10:30:25 -05:00
|
|
|
obj.canvas:hide()
|
2022-04-16 16:50:03 -04:00
|
|
|
end
|
2021-08-30 15:36:04 -06:00
|
|
|
|
2022-04-16 16:50:03 -04:00
|
|
|
-- Use escape to exit launcher mode
|
|
|
|
self.launcher:bind("", "escape", function()
|
|
|
|
self.launcher:exit()
|
|
|
|
end)
|
2021-12-27 22:31:30 -07:00
|
|
|
|
2022-04-16 16:50:03 -04:00
|
|
|
-- Launcher shortcuts
|
2023-03-08 10:30:25 -05:00
|
|
|
self.launcher:bind("ctrl", "space", function()
|
|
|
|
end)
|
2022-04-16 16:50:03 -04:00
|
|
|
self.launcher:bind("", "return", function()
|
2022-12-20 18:22:24 -07:00
|
|
|
self:switch("@kitty@")
|
2022-04-16 16:50:03 -04:00
|
|
|
end)
|
|
|
|
self.launcher:bind("", "C", function()
|
|
|
|
self:switch("Calendar.app")
|
|
|
|
end)
|
|
|
|
self.launcher:bind("", "D", function()
|
2022-12-20 18:22:24 -07:00
|
|
|
self:switch("@discord@")
|
2022-04-16 16:50:03 -04:00
|
|
|
end)
|
|
|
|
self.launcher:bind("", "E", function()
|
|
|
|
self:switch("Mail.app")
|
|
|
|
end)
|
2022-04-22 10:12:28 -04:00
|
|
|
self.launcher:bind("", "U", function()
|
|
|
|
self:switch("Music.app")
|
|
|
|
end)
|
2022-04-16 16:50:03 -04:00
|
|
|
self.launcher:bind("", "F", function()
|
2022-12-20 18:22:24 -07:00
|
|
|
self:switch("@firefox@")
|
2022-04-16 16:50:03 -04:00
|
|
|
end)
|
2022-04-21 17:26:34 -04:00
|
|
|
self.launcher:bind("", "H", function()
|
|
|
|
self:switch("Hammerspoon.app")
|
|
|
|
end)
|
2022-04-16 16:50:03 -04:00
|
|
|
self.launcher:bind("", "G", function()
|
|
|
|
self:switch("Mimestream.app")
|
|
|
|
end)
|
|
|
|
self.launcher:bind("", "M", function()
|
|
|
|
self:switch("Messages.app")
|
|
|
|
end)
|
|
|
|
self.launcher:bind("", "O", function()
|
|
|
|
self:switch("Obsidian.app")
|
|
|
|
end)
|
|
|
|
self.launcher:bind("", "P", function()
|
|
|
|
self:switch("System Preferences.app")
|
|
|
|
end)
|
|
|
|
self.launcher:bind("", "R", function()
|
2023-03-22 16:20:30 -04:00
|
|
|
hs.console.clearConsole()
|
2022-04-16 16:50:03 -04:00
|
|
|
hs.reload()
|
|
|
|
end)
|
|
|
|
self.launcher:bind("", "S", function()
|
2023-03-09 10:45:00 -05:00
|
|
|
self:switch("@slack@")
|
2022-04-16 16:50:03 -04:00
|
|
|
end)
|
|
|
|
self.launcher:bind("", "Z", function()
|
|
|
|
self:switch("zoom.us.app")
|
|
|
|
end)
|
2021-08-30 15:36:04 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
function obj:switch(app)
|
2022-04-16 16:50:03 -04:00
|
|
|
hs.application.launchOrFocus(app)
|
|
|
|
self.launcher:exit()
|
2021-08-30 15:36:04 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
return obj
|