dotfiles/modules/darwin/hammerspoon/Spoons/Launcher.spoon/init.lua

112 lines
3.1 KiB
Lua
Raw Permalink Normal View History

2021-08-30 21:36:04 +00:00
--- === Launcher ===
local obj = {}
2021-08-30 21:36:04 +00:00
obj.__index = obj
-- Metadata
obj.name = "Launcher"
obj.version = "0.1"
obj.license = "MIT - https://opensource.org/licenses/MIT"
2021-08-30 21:36:04 +00:00
local screen = hs.screen.primaryScreen()
local switcherWidth = 500
2022-04-16 20:50:03 +00:00
2021-08-30 21:36:04 +00:00
function obj:init()
2022-04-16 20:50:03 +00:00
-- Begin launcher mode
2022-04-21 18:22:02 +00:00
if self.launcher == nil then
self.launcher = hs.hotkey.modal.new("ctrl", "space")
print(self.canvas)
print(obj.canvas)
2022-04-21 18:22:02 +00:00
end
2021-08-30 21:36:04 +00:00
2022-04-16 20:50:03 +00:00
-- Behaviors on enter
function self.launcher:entered()
-- hs.alert("Entered mode")
obj.canvas = hs.canvas.new({
x = (screen:fullFrame().x + screen:fullFrame().w) / 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",
}
obj.canvas:show()
2022-04-16 20:50:03 +00:00
end
2022-04-16 20:50:03 +00:00
-- Behaviors on exit
function self.launcher:exited()
-- hs.alert("Exited mode")
obj.canvas:delete(0.2)
2022-04-16 20:50:03 +00:00
end
2021-08-30 21:36:04 +00:00
2022-04-16 20:50:03 +00:00
-- Use escape to exit launcher mode
self.launcher:bind("", "escape", function()
self.launcher:exit()
end)
2022-04-16 20:50:03 +00:00
-- Launcher shortcuts
self.launcher:bind("ctrl", "space", function() end)
2022-04-16 20:50:03 +00:00
self.launcher:bind("", "return", function()
self:switch("@wezterm@")
2022-04-16 20:50:03 +00:00
end)
self.launcher:bind("", "C", function()
self:switch("Calendar.app")
end)
self.launcher:bind("shift", "D", function()
hs.execute("launchctl remove com.paloaltonetworks.gp.pangps")
hs.execute("launchctl remove com.paloaltonetworks.gp.pangpa")
hs.alert.show("Disconnected from GlobalProtect", nil, nil, 4)
self.launcher:exit()
end)
2022-04-16 20:50:03 +00:00
self.launcher:bind("", "E", function()
self:switch("Mail.app")
end)
self.launcher:bind("", "F", function()
self:switch("@firefox@")
2022-04-16 20:50:03 +00:00
end)
2022-04-21 21:26:34 +00:00
self.launcher:bind("", "H", function()
self:switch("Hammerspoon.app")
end)
2022-04-16 20:50:03 +00:00
self.launcher:bind("", "M", function()
self:switch("Messages.app")
end)
self.launcher:bind("", "O", function()
self:switch("@obsidian@")
2022-04-16 20:50:03 +00:00
end)
self.launcher:bind("", "P", function()
self:switch("System Preferences.app")
end)
self.launcher:bind("shift", "P", function()
hs.execute("launchctl load /Library/LaunchAgents/com.paloaltonetworks.gp.pangps.plist")
hs.execute("launchctl load /Library/LaunchAgents/com.paloaltonetworks.gp.pangpa.plist")
hs.alert.show("Reconnecting to GlobalProtect", nil, nil, 4)
self.launcher:exit()
end)
2022-04-16 20:50:03 +00:00
self.launcher:bind("", "R", function()
2023-03-22 20:20:30 +00:00
hs.console.clearConsole()
2022-04-16 20:50:03 +00:00
hs.reload()
end)
self.launcher:bind("", "S", function()
self:switch("@slack@")
2022-04-16 20:50:03 +00:00
end)
self.launcher:bind("", "Z", function()
self:switch("zoom.us.app")
end)
2021-08-30 21:36:04 +00:00
end
function obj:switch(app)
2022-04-16 20:50:03 +00:00
hs.application.launchOrFocus(app)
self.launcher:exit()
2021-08-30 21:36:04 +00:00
end
return obj