Hotkeys for searching the Cocoa docs

Here's how to create global hotkeys for instantly searching the Cocoa docs using Dash, AppKiDo, or Xcode.

This whole exercise started when I saw this tweet by Matt Gemmell:

There’s a kind of zen calmness to the docs page for NSNull.

Since I have Dash installed, and since I've assigned a hotkey to its "Look up in Dash" system service, it took me all of two seconds, maybe less, to confirm this. I selected the word "NSNull", hit the hotkey, and there it was. Matt's right.

Here's where I assign the Dash hotkey, in System Preferences > Keyboard > Keyboard Shortcuts > Services:

Look up in dash

"Look up in AppKiDo"

UPDATE: You can ignore the rest of this post. I added a real system service to AppKiDo in version 0.991. You can configure a hotkey for the service just as you would for any other system service.

This got me thinking about adding a similar system service to AppKiDo. I wondered whether I should try to squeeze that into the upcoming release (which will have a few small changes, most importantly to point to appkido.com instead of MobileMe). But then I realized I could just use a keyboard macro utility (in my case, Keyboard Maestro) to accomplish the same thing. I created a keyboard shortcut that does the following: * Type Command-E, which is Mac standard for "Use Selection for Find". This puts whatever text is selected in your current app into the Find pasteboard. * Activate AppKiDo, which now displays the selected string in the Search field. * Type Shift-Command-F (which selects the Search field) and Return (which initiates a search). Look up in appkido Now I can look up NSNull in AppKiDo the same way as I did in Dash, by selecting text and hitting a key. This assumes AppKiDo has a browser window open and frontmost, but for me that's always the case. To search AppKiDo-for-iPhone, you'd need a separate hotkey. If you want to get technical, AppKiDo doesn't show the whole docs page, only one part of it at a time. To see the whole HTML page, and thus appreciate its zen-ness, you'd have to right-click and select "Open Page in Browser". And then you'd have to dismiss a dialog in Safari because that file is quarantined. So now we're talking maybe five seconds. Dash wins handily at displaying the whole page. ## The YoruFukurou problem While testing my "Look up in AppKiDo" shortcut, I discovered that YoruFukurou doesn't support the "Use Selection for Find" operation. It bugged me to have this edge case, so I created a variant of the shortcut just for YoruFukurou:
  • Type Command-C (copy to the clipboard).
  • Run the following AppleScript to activate AppKiDo and do the search.
    tell application "AppKiDo"
        activate
        search (the clipboard)
    end
Just for yorufukurou This uses the fact that AppKiDo can be scripted to do a search. I also use Keyboard Maestro's ability to have a keyboard shortcut do different things depending on which application is active, so I don't have to remember a separate shortcut for the YoruFukurou case. The reason I don't use this approach in all cases is that Command-C blows away the contents of the copy-paste pasteboard, whereas Command-E uses a different pasteboard. ## "Look up in Xcode" Finally, just for grins, I thought I'd do a similar shortcut for doing the search in Xcode. Xcode is very slow at searching the documentation, but it's useful for doing full-text searches of the complete documentation, as opposed to searching only the API reference docs based on the name of the API symbol. This shortcut uses the fact that in Xcode, hitting Shift-Option-Command-/ (aka Option-Command-?) always causes the doc window to be open with the Search field selected. * Type Command-C to copy the desired search string into the clipboard. * Activate Xcode. * Type Shift-Option-Command-/ to bring up the doc window, and Command-V to paste the search string into the search field. Look up in xcode Note that *within* Xcode there's already a shortcut for searching the docs for the selected text: Control-Option-Command-/ (last item in the Help menu).

[UPDATE: I'm getting better about editing my posts after publishing them, but I couldn't resist making a few changes. Nothing major.]

2 thoughts on “Hotkeys for searching the Cocoa docs

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.