Detect Alfred popup

207 views
Skip to first unread message

Sean Mackesey

unread,
Mar 21, 2017, 11:00:00 PM3/21/17
to Hammerspoon
Alfred is a popular app that supports launching applications, searching for files, and much other functionality. The primary interface to Alfred is a kind of "popup" that is invoked with a hotkey. I am trying to listen for the activation of the popup in Hammerspoon, but can't figure out how to do so because invoking the Alfred popup does not "activate" the Alfred application. Is there any way to detect Alfred's activation?

Tomislav Filipcic

unread,
Mar 27, 2017, 12:34:05 PM3/27/17
to Hammerspoon
If all else fails I usually try listening for notifications using hs.distributednotifications. There might be notification from Alfred when the popup is invoked.

Chris Jones

unread,
Mar 27, 2017, 12:34:58 PM3/27/17
to Sean Mackesey, Hammerspoon
Hey

You might take a look at hs.windowfilter, but its underlying mechanisms are pretty much the hs.application watcher, so it may also not see anything useful.

Cheers,
Chris

On 22 March 2017 at 03:00, Sean Mackesey <s.mac...@gmail.com> wrote:
Alfred is a popular app that supports launching applications, searching for files, and much other functionality. The primary interface to Alfred is a kind of "popup" that is invoked with a hotkey. I am trying to listen for the activation of the popup in Hammerspoon, but can't figure out how to do so because invoking the Alfred popup does not "activate" the Alfred application. Is there any way to detect Alfred's activation?

--
You received this message because you are subscribed to the Google Groups "Hammerspoon" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hammerspoon+unsubscribe@googlegroups.com.
To post to this group, send email to hamme...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/hammerspoon/8ac89b61-0497-4d58-a69d-f1f7371d53ba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Cheers,

Chris

Sean Mackesey

unread,
Mar 27, 2017, 2:51:47 PM3/27/17
to Hammerspoon, s.mac...@gmail.com
Thanks Tomislav and Chris. I tried both of your suggestions:

- I could not detect any distributed notifications from activating the Alfred popup
- Activating the Alfred popup *does* create a window, but I ran into problems watching it (see below)

I created a window filter to watch the Alfred application and tried subscribing to multiple pairs of events to detect popup activation/inactivation. Detection worked, but would quickly become very laggy. When I would reload Hammerspoon, the detection callbacks fired immediately on activation/inactivation of the popup. However, as soon as I would activate another application, all of a sudden some of my callbacks would become slow. The callback for activation of the window would always fire right away, but the callback for deactivation would have a 1-2sec lag before firing. I found that unrelated eventTap callbacks would also became delayed. On further experimentation, I observed this behavior for any subscription to any windowFilter at all. At the same time, my Hammerspoon console prints messages like this:

2017-03-27 11:45:24: 11:45:24 ** Warning:   wfilter: No accessibility access to app Slack Helper (no watcher pid)

It does this for "Slack Helper" and a few other apps. In the past, I've run `hs.window._timed_allWindows()` when having issues with window slowness, but I didn't see any interesting results this time (no laggy apps).

So in summary, the suggestion to use `windowFilter` would work, but it appears that something about `windowFilter` is either fundamentally broken or just incompatible with my system? Because any window subscription causes all of my Hammerspoon callbacks to lag.

Thanks.

On Monday, March 27, 2017 at 9:34:58 AM UTC-7, Chris Jones wrote:
Hey

You might take a look at hs.windowfilter, but its underlying mechanisms are pretty much the hs.application watcher, so it may also not see anything useful.

Cheers,
Chris
On 22 March 2017 at 03:00, Sean Mackesey <s.mac...@gmail.com> wrote:
Alfred is a popular app that supports launching applications, searching for files, and much other functionality. The primary interface to Alfred is a kind of "popup" that is invoked with a hotkey. I am trying to listen for the activation of the popup in Hammerspoon, but can't figure out how to do so because invoking the Alfred popup does not "activate" the Alfred application. Is there any way to detect Alfred's activation?

--
You received this message because you are subscribed to the Google Groups "Hammerspoon" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hammerspoon...@googlegroups.com.

To post to this group, send email to hamme...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/hammerspoon/8ac89b61-0497-4d58-a69d-f1f7371d53ba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Cheers,

Chris

Tomislav Filipcic

unread,
Mar 27, 2017, 2:59:12 PM3/27/17
to Hammerspoon, s.mac...@gmail.com
About the warning: it's because Slack is an Electron app, basically a web app wrapped in a native shell. Because of that it doesn't support accessibility access. You get the same warning for the Atom editor, Spotify, etc. You can ignore those warnings.

Share your code so we can take a look and maybe try to reproduce.

Sean Mackesey

unread,
Mar 27, 2017, 3:34:16 PM3/27/17
to Hammerspoon, s.mac...@gmail.com
It appears that this problem specifically involves the destruction of the Alfred popup window. It seems to slow down the window filter system, even if I'm not even to subscribed to events on Alfred. Below is a simple hammerspoon/init.lua that produces this problem on my system (though you also need Alfred installed):

TARGET_APP = 'Google Chrome'
appFilter
= hs.window.filter.new(false)
appFilter
:setAppFilter(TARGET_APP, true)
appFilter
:subscribe({hs.window.filter.windowUnfocused}, function (win, appName, evt)
 
print(string.format("WINDOW EVENT OCCURRED", 'SOMEWINDOW', appName))
end, true)


modifierKeyTap
= hs.eventtap.new({hs.eventtap.event.types['flagsChanged']}, function (event)
 
print ('flag changed!')
end)
modifierKeyTap
:start()

Try these instructions:

- start up hammerspoon with the Hammerspoon console visible
- activate and deactivate the Alfred popup using the configured combination (mine is Ctrl-Space)
- you should see "flag changed!" in the Hammerspoon console from the modifierKeyTap every time you press or release Ctrl
- now activate the Hammerspoon application
- activate/deactivate the Alfred popup as before; there will now be a ~2-second lag before the final "flag changed!" is printed when you release Ctrl to deactivate the popup

There is also this error message:

2017-03-27 12:20:17: 12:20:17 ** Warning:   wfilter: Alfred 3 (132) is not registered yet


Note that it doesn't matter what I set `TARGET_APP` to, the problem is the same.
Reply all
Reply to author
Forward
0 new messages