How do I open a directory in Hammerspoon?

I would like to open a directory on Hammerspoon using a keyboard shortcut. To open any applications with a shortcut, you use the following:

hs.hotkey.bind({"ctrl"}, "n", function()
    hs.application.launchOrFocus("Safari")
    end
)

      

However, this does not work on the filesystem. For example, if you want to open ~/Dropbox

, what method should you follow to open the application?

+3


source to share


1 answer


I'm not sure if there is an API specifically suited for this task, but I found that one solution is to bind keys to execute a shell command on Hammerspoon (via hs.execute()

).

local function directoryLaunchKeyRemap(mods, key, dir)
    local mods = mods or {}
    hs.hotkey.bind(mods, key, function()
        local shell_command = "open " .. dir
        hs.execute(shell_command)
    end)
end

directoryLaunchKeyRemap({"ctrl"}, "1", "/Applications") 

      



This allows you to open the directory /Applications

via + 1.

+1


source







All Articles