macosfilterluahammerspoon

Hammerspoon: filter application in use


I bind some key to execute script. I need to activite bind only when Visual Studio Code window is focused.

I see Hammerspoon filters functions but I don't understand how use it.

Application name: Code

hs.hotkey.bind({"ctrl"}, "b", function()
    local codeWindowFilter = hs.window.filter:setAppFilter('Code')
    codeWindowFilter:isAppAllowed("Code", function()

        mycode here

    end)
end)

but I get the error attempt to call a nil value (method 'setAppFilter')

Is this the correct way? Is there way to put all bind into approved filter?

Thnak you in advance


Solution

  • The final solution is that one:

    local frontmostApplication = hs.application.frontmostApplication()
    
    if frontmostApplication and frontmostApplication:name() == "Code" then
    
       {my code here}
    
    end