feat(hammerspoon): move application shortcuts to Hammerspoon

This commit is contained in:
Stefan Imhoff
2023-07-02 11:59:48 +02:00
parent 784a8240fb
commit 1df47a17f2
2 changed files with 91 additions and 54 deletions

View File

@@ -110,6 +110,50 @@ function GetAllValidWindows()
return windows
end
-- Launch application or toggle it
function launchToggleApplication(applicationName)
local app = hs.application.find(applicationName)
if app then
local appWindows = app:visibleWindows()
if #appWindows > 0 then
local focusedWindow = app:focusedWindow()
if focusedWindow then
if app:isHidden() then
app:unhide()
else
-- Some apps don't allow hiding, so Apple Script is needed
if app:hide() == false then
hideApplicationWithAppleScript(app)
else
app:hide()
end
end
else
app:activate()
end
else
app:activate()
end
else
hs.application.launchOrFocus(applicationName)
end
end
-- Hide application with AppleScript
function hideApplicationWithAppleScript(app)
local appName = app:name()
local hideScript = [[
tell application "Finder"
set visible of process "%s" to false
end tell
]]
local formattedScript = string.format(hideScript, appName)
hs.osascript.applescript(formattedScript)
end
-- Auto Reload Config
function ReloadConfig(files)
DoReload = false

View File

@@ -1,6 +1,8 @@
require("functions")
require("caffeine")
rawset(_G, "hs", hs or {})
local application = hs.application
local window = hs.window
local layout = hs.layout
@@ -25,10 +27,11 @@ hints.showTitleThresh = 0
application.enableSpotlightForNameSearches(true)
------------
-- Aliase --
-- Aliases --
------------
-- Keys
local KEY_HYPER = { "", "", "", "" }
local KEY_AM = { "", "" }
local KEY_CA = { "", "" }
local KEY_CAM = { "", "", "" }
@@ -36,7 +39,6 @@ local KEY_CM = { "⌃", "⌘" }
local KEY_SAM = { "", "", "" }
local KEY_SC = { "", "" }
local KEY_SCA = { "", "", "" }
local KEY_SCAM = { "", "", "", "" }
local KEY_SCM = { "", "", "" }
-- Displays
@@ -105,47 +107,41 @@ local LAYOUT_SINGLE = {
-- Key Bindings --
------------------
-- Movement hotkeys (Moved to Raycast -- keep for later)
-- stylua: ignore start
-- Movement hotkeys
-- hotkey.bind(KEY_AM, "down", function() nudge(0, 100) end)
-- hotkey.bind(KEY_AM, "up", function() nudge(0, -100) end)
-- hotkey.bind(KEY_AM, "right", function() nudge(100, 0) end)
-- hotkey.bind(KEY_AM, "left", function() nudge(-100, 0) end)
-- Resize hotkeys
hotkey.bind(KEY_SAM, "up", function()
Yank(0, -100)
end)
hotkey.bind(KEY_SAM, "down", function()
Yank(0, 100)
end)
hotkey.bind(KEY_SAM, "right", function()
Yank(100, 0)
end)
hotkey.bind(KEY_SAM, "left", function()
Yank(-100, 0)
end)
hotkey.bind(KEY_SAM, "up", function() Yank(0, -100) end)
hotkey.bind(KEY_SAM, "down", function() Yank(0, 100) end)
hotkey.bind(KEY_SAM, "right", function() Yank(100, 0) end)
hotkey.bind(KEY_SAM, "left", function() Yank(-100, 0) end)
-- Push to screen edge (Moved to Raycast -- keep for later)
-- Push to screen edge
-- hotkey.bind(KEY_CAM, "left", function() Push(0, 0, 0.5, 1) end)
-- hotkey.bind(KEY_CAM, "right", function() Push(0.5, 0, 0.5, 1) end)
-- hotkey.bind(KEY_CAM, "up", function() Push(0, 0, 1, 0.5) end)
-- hotkey.bind(KEY_CAM, "down", function() Push(0, 0.5, 1, 0.5) end)
-- Centered window with some room to see the desktop (Moved to Raycast -- keep for later)
-- Centered window with some room to see the desktop
-- hotkey.bind(KEY_SCM, "l", function() Push(0.05, 0.05, 0.9, 0.9) end)
-- hotkey.bind(KEY_SCM, "m", function() Push(0.1, 0.1, 0.8, 0.8) end)
-- hotkey.bind(KEY_SCM, "s", function() Push(0.15, 0.15, 0.7, 0.7) end)
-- Fullscreen (Moved to Raycast -- keep for later)
-- Fullscreen
-- hotkey.bind(KEY_CAM, "0", function() Push(0, 0, 1, 1) end)
-- Quarter Screens (Moved to Raycast -- keep for later)
-- Quarter Screens
-- hotkey.bind(KEY_CAM, "q", function() Push(0, 0, 0.5, 0.5) end)
-- hotkey.bind(KEY_CAM, "w", function() Push(0.5, 0, 0.5, 0.5) end)
-- hotkey.bind(KEY_CAM, "a", function() Push(0, 0.5, 0.5, 0.5) end)
-- hotkey.bind(KEY_CAM, "s", function() Push(0.5, 0.5, 0.5, 0.5) end)
-- Part Screens (Moved to Raycast -- keep for later)
-- Part Screens
-- hotkey.bind(KEY_CAM, "4", function() Push(0, 0, 0.6, 1) end)
-- hotkey.bind(KEY_CAM, "5", function() Push(0, 0, 0.4, 1) end)
-- hotkey.bind(KEY_CAM, "6", function() Push(0.4, 0, 0.6, 1) end)
@@ -164,7 +160,7 @@ end)
-- hotkey.bind(KEY_CM, "right", function() window.focusedWindow():moveOneScreenEast() end)
-- hotkey.bind(KEY_CM, "up", function() window.focusedWindow():moveOneScreenNorth() end)
-- Move a window between monitors (change to fullscreen) (Moved to Raycast -- keep for later)
-- Move a window between monitors (change to fullscreen)
-- hotkey.bind(KEY_SCM, "1", function() window.focusedWindow():moveOneScreenNorth(); push(0, 0, 1, 1) end)
-- hotkey.bind(KEY_SCM, "2", function() window.focusedWindow():moveOneScreenSouth(); push(0, 0, 1, 1) end)
-- hotkey.bind(KEY_SCM, "3", function() window.focusedWindow():moveOneScreenWest(); window.focusedWindow():moveOneScreenWest(); push(0, 0, 1, 1) end)
@@ -177,47 +173,44 @@ end)
-- hotkey.bind(KEY_SCM, "l", function() window.focusedWindow():moveOneScreenEast(); push(0, 0, 1, 1) end)
-- hotkey.bind(KEY_SCM, "h", function() window.focusedWindow():moveOneScreenWest(); window.focusedWindow():moveOneScreenWest(); push(0, 0, 1, 1) end)
-- Application shortcuts (Moved to Raycast -- keep for later)
-- hotkey.bind(KEY_SC, "R", function() application.launchOrFocus("kitty") end)
-- hotkey.bind(KEY_SCAM, "A", function() application.launchOrFocus("Affinity Designer") end)
-- hotkey.bind(KEY_SCAM, "B", function() application.launchOrFocus("Brave Browser") end)
-- hotkey.bind(KEY_SCAM, "C", function() application.launchOrFocus("Visual Studio Code") end)
-- hotkey.bind(KEY_SCAM, "D", function() application.launchOrFocus("DEVONthink 3") end)
-- hotkey.bind(KEY_SCAM, "F", function() application.launchOrFocus("Reeder") end)
-- hotkey.bind(KEY_SCAM, "K", function() application.launchOrFocus("Calendar") end)
-- hotkey.bind(KEY_SCAM, "M", function() application.launchOrFocus("MindNode") end)
-- hotkey.bind(KEY_SCAM, "N", function() application.launchOrFocus("Messages") end)
-- hotkey.bind(KEY_SCAM, "O", function() application.launchOrFocus("Obsidian") end)
-- hotkey.bind(KEY_SCAM, "P", function() application.launchOrFocus("Bitwarden") end)
-- hotkey.bind(KEY_SCAM, "R", function() application.launchOrFocus("Raindrop.io.app") end)
-- hotkey.bind(KEY_SCAM, "S", function() application.launchOrFocus("Slack") end)
-- hotkey.bind(KEY_SCAM, "T", function() application.launchOrFocus("Things3") end)
-- hotkey.bind(KEY_SCAM, "W", function() application.launchOrFocus("iA Writer") end)
-- hotkey.bind(KEY_SCAM, "Y", function() application.launchOrFocus("Music") end)
-- Application shortcuts
hotkey.bind(KEY_SC, "r", function() launchToggleApplication("Wezterm") end)
hotkey.bind(KEY_SC, "w", function() launchToggleApplication("kitty") end)
hotkey.bind(KEY_HYPER, "a", function() launchToggleApplication("Arc") end)
hotkey.bind(KEY_HYPER, "b", function() launchToggleApplication("Brave Browser") end)
hotkey.bind(KEY_HYPER, "c", function() launchToggleApplication("Visual Studio Code") end)
hotkey.bind(KEY_HYPER, "d", function() launchToggleApplication("DEVONthink 3") end)
hotkey.bind(KEY_HYPER, "e", function() launchToggleApplication("Eagle") end)
hotkey.bind(KEY_HYPER, "f", function() launchToggleApplication("Reeder") end)
hotkey.bind(KEY_HYPER, "g", function() launchToggleApplication("Signal") end)
hotkey.bind(KEY_HYPER, "i", function() launchToggleApplication("Messages") end)
hotkey.bind(KEY_HYPER, "m", function() launchToggleApplication("Mail") end)
hotkey.bind(KEY_HYPER, "n", function() launchToggleApplication("MindNode") end)
hotkey.bind(KEY_HYPER, "o", function() launchToggleApplication("Obsidian") end)
hotkey.bind(KEY_HYPER, "r", function() launchToggleApplication("Raindrop.io") end)
hotkey.bind(KEY_HYPER, "s", function() launchToggleApplication("Spotify") end)
hotkey.bind(KEY_HYPER, "t", function() launchToggleApplication("Things") end)
hotkey.bind(KEY_HYPER, "u", function() launchToggleApplication("Kalender") end)
hotkey.bind(KEY_HYPER, "w", function() launchToggleApplication("iA Writer") end)
hotkey.bind(KEY_HYPER, "x", function() launchToggleApplication("Microsoft Teams") end)
-- Place red circle around mouse
hotkey.bind(KEY_SCAM, "space", MouseHighlight)
hotkey.bind(KEY_CAM, "space", MouseHighlight)
-- Hints
hotkey.bind(KEY_HYPER, "space", function() hints.windowHints(GetAllValidWindows()) end)
-- Manual config reloading (from getting started guide):
hotkey.bind(KEY_CAM, "delete", function()
hs.reload()
end)
hotkey.bind(KEY_HYPER, "delete", function() hs.reload() end)
-- Focus (Moved to Raycast -- keep for later)
-- Focus
-- hotkey.bind(KEY_CAM, 'k', function() window.focusedWindow():focusWindowNorth() end)
-- hotkey.bind(KEY_CAM, 'j', function() window.focusedWindow():focusWindowSouth() end)
-- hotkey.bind(KEY_CAM, 'l', function() window.focusedWindow():focusWindowEast() end)
-- hotkey.bind(KEY_CAM, 'h', function() window.focusedWindow():focusWindowWest() end)
-- Hints
hotkey.bind(KEY_CAM, "space", function()
hints.windowHints(GetAllValidWindows())
end)
-- Layouts
hotkey.bind(KEY_SCAM, "1", function()
layout.apply(LAYOUT_SINGLE)
end)
hotkey.bind(KEY_SCAM, "2", function()
layout.apply(LAYOUT_DUAL)
end)
hotkey.bind(KEY_HYPER, "1", function() layout.apply(LAYOUT_SINGLE) end)
hotkey.bind(KEY_HYPER, "2", function() layout.apply(LAYOUT_DUAL) end)
-- stylua: ignore end