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!
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!
Most helpful comment
I believe using hs.application.watcher is a better way. Thus we can hook
activated/deactivatedevent 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.