hammerspoon
hammerspoon copied to clipboard
How can I run shortcuts via the terminal instead of using keys?
I am writing in the init.lua
script.
function openObsidianAndSearch()
-- Open Obsidian
hs.application.launchOrFocus("Obsidian")
-- Wait for a moment to ensure Obsidian has focus
hs.timer.doAfter(1, function()
-- Send Cmd+Shift+F to Obsidian
hs.eventtap.keyStroke({"cmd", "shift"}, "F")
end)
end
I want to run it from the terminal.
hs -c 'openObsidianAndSearch()'
fish: Unknown command: hs
I installed Hammerspoon by brew install --cask hammerspoon
.
The path of the hs
executable is:
/Applications/Hammerspoon.app/Contents/Frameworks/hs/hs
so, you may want to include it in your PATH
or make a symlink.
There's also a man page:
/Applications/Hammerspoon.app/Contents/Resources/man/hs.man
PS: I didn't even know Hammerspoon had an executable! 😎
EDIT / IMPORTANT
See the hs.ipc docs on how to install and use hs
.