crankd doesn't handle nsdistributednotifications, now it does
I have GeekTool installed(v3 is applescriptable. In particular, you can
tell it to refresh certain geeklets, allowing one to update a geeklet on an
event supported by crankd) and I wanted a way to avoid polling for iTunes
track information because that drained my macbook's battery pretty quickly
so I took a look at crankd. I quickly realized that it didn't support
NSDistributedNotifications so I wrote in support for that particular
notification type.
When the initial patch was finished, I discovered that there might be a
quirk(maybe this "quirk" is by design, I don't know) with the way the
NSDistributedNotificationCenter handles an application launch/quit. I
found that if you're subscribed to an event and the application emitting
that event quits and subsequently relaunches, the handler will never be
called again.
I wrote another patch to fix this problem. It adds a config option for
NSDistrbutedNotifications, process, that tells crankd to subscribe to
ApplicationDidLaunch events with a special handler, do_reload. When an
application is launched, the do_reload handler is called and checks the
process name against the config option. If they match, the
DistNotification is reloaded and hence the handler is valid once again.
This handler won't replace any existing appdidlaunch events.
The patched version of crankd is attached to this issue with changes marked
by the comment "# distnot patch: change" (where change is what was added).
FYI: All spaces were converted to tabs.
btw, I wanted to take this opportunity to thank you for crankd, it's been
working amazingly well for me :D.
Original issue reported on code.google.com by [email protected] on 10 Dec 2009 at 9:34
Attachments:
edit: remove the line containing "del RELAUNCH_IDS[event]" otherwise the
appdidlaunch
event will be lost
Original comment by [email protected] on 10 Dec 2009 at 9:52
I applied the changes in the original attachment to my GitHub fork[1] of this
project. The PATCH is attached (and I'd like to rap the author's knuckles with
a hammer for not providing a patch AND for changing spaces to tabs). Hopefully
this is a little more useful.
[1]; https://github.com/blalor/pymacadmin
Original comment by [email protected] on 14 Mar 2011 at 2:55
Attachments:
ouch! Knuckles are a bit sore :( Sorry 'bout that, I think this was only my
second FOSS contribution ever.
Original comment by [email protected] on 14 Mar 2011 at 4:16
I guess I forgot to be gracious about you doing the work in the first place.
Sorry about that; it works very well! :-) I extended it a bit by allowing an
event key of "*" to be translated to None, which allows *all* events to be
captured. The dispatcher needs a little more work to provide access to the
entire notification object, but that's trivial.
Original comment by [email protected] on 14 Mar 2011 at 5:04
no need to apologize :) I'm glad it was merged into trunk and that other
people have found it useful.
Original comment by [email protected] on 15 Mar 2011 at 9:45
It's not been merged into the trunk, it's just in my GitHub fork. But I did
find it useful!
Original comment by [email protected] on 15 Mar 2011 at 10:16