hammerspoon icon indicating copy to clipboard operation
hammerspoon copied to clipboard

How can I run shortcuts via the terminal instead of using keys?

Open mxcdh opened this issue 1 year ago • 1 comments

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.

mxcdh avatar Oct 15 '23 09:10 mxcdh

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.

piechologist avatar Oct 16 '23 18:10 piechologist