TIL: using hammerspoon to launch any app with a hotkey
Published by Patrick Arminio on
I've recently started using Logseq for writing daily notes and I found myself needing to open it very often (which is a good thing I hope), so I decided to spend a bit of time making a hotkey that opens Logseq and shows it in the active desktop (I wanted to prevent any kind of animation).
Iโve recently started using Logseq for writing daily notes and I found myself needing to open it very often (which is a good thing I hope), so I decided to spend a bit of time making a hotkey that opens Logseq and shows it in the active desktop (I wanted to prevent any kind of animation).
Iโve used hammerspoon and hs.spaces to make this work. It did take a bit of time to figure out how to move the app to my active desktop, but in the end I got it working quite well. The code is actually pretty short, so Iโll probably start using this for other apps soon.
Hereโs the code if youโre curious:
spaces = require("hs.spaces")
hs.hotkey.bind({"cmd", "alt", "ctrl", "shift"}, "L", function()
local app = hs.application.find("logseq")
if app == nil then
hs.alert.show("Launching logseq")
hs.application.launchOrFocus("logseq")
elseif app:isFrontmost() then
app:hide()
else
local win = app:mainWindow()
local activeSpaces = spaces.activeSpaces()
spaces.moveWindowToSpace(win:id(), spaces.activeSpaceOnScreen())
win:focus()
end
end)
Basically every time I press CMD+ALT+CTRL+SHIFT+L I trigger the code that checks if Logseq is running, if is it toggles it based on its status, otherwise it starts the app ๐