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条回答
兄弟一词,经得起流年.
2楼-- · 2020-07-06 07:34

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
} 
查看更多
登录 后发表回答