How to hook the OS X dictionary

2020-07-06 07:19发布

问题:

on osx lion, you can control-command-d or triple-tap on a word that your mouse is pointed to in any app to launch a popover dictionary. i want to make an app to track the words a user is looking up in the dictionary.

how do i observe the event where the user does control-command-d or triple-tap to launch the popover dictionary?

I understand that the specific API for this is HIDictionaryWindowShow.

回答1:

You can use popoverDidShow:

- (void)awakeFromNib {
    NSNotificationCenter* notificationCenter = [NSNotificationCenter defaultCenter];
    [notificationCenter addObserver:self selector:@selector(popoverDidShow:)
                            name:NSPopoverDidShowNotification object:nil];
}

// dictionary is shown or another NSPopover
- (void)popoverDidShow:(NSNotification*)notify { 
    //your code
}