📜

TIL: using hammerspoon to launch any app with a hotkey

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 😊

Webmentions

No replies found! Tweet about this post, and it will show up here! ☝