Hammerspoon: Binding keys in specific apps

Created on 8 Jun 2017  Â·  3Comments  Â·  Source: Hammerspoon/hammerspoon

What's the best way to get hotkey working only in specific app(s)?

I started naively:

using hs.window.filter with subscribe, something like:

hs.window.filter.new{'Google Chrome'}
:subscribe(hs.window.filter.windowFocused, function()
   doTheBindings(chromeKeys)
end)
:subscribe(hs.window.filter.windowUnfocused, function()
   hs.hotkey.disableAll(chromeKeys)
end)

and it does work. But! If I add more than just one app it gets extremely slow. Can you guys suggest a better way? Thanks!

Most helpful comment

I believe using hs.application.watcher is a better way. Thus we can hook activated/deactivated event for adding or removing the keybindings, or creating dynamic menuitems. I had the idea for quite a time, but I'm too lazy to move forward…

I'll get time in recent days to see what I can do about this.

All 3 comments

It seems one of the reasons why it turned out to be so painfully slow was this:

:setAppFilter('Emacs', {allowRoles='*'})

I have managed to make it bearable by specifying exact values:

:setAppFilter('Emacs', {allowRoles={'AXUnknown', 'AXStandardWindow'}})

I'm still curious if there's a better way

I believe using hs.application.watcher is a better way. Thus we can hook activated/deactivated event for adding or removing the keybindings, or creating dynamic menuitems. I had the idea for quite a time, but I'm too lazy to move forward…

I'll get time in recent days to see what I can do about this.

@ashfinal I didn't have time in the past few weeks to play with HS, indeed hs.application.watcher is better suited for what I'm trying to do. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aaronjensen picture aaronjensen  Â·  3Comments

iliyang picture iliyang  Â·  4Comments

Pancia picture Pancia  Â·  4Comments

latenitefilms picture latenitefilms  Â·  4Comments

lazandrei19 picture lazandrei19  Â·  4Comments