Update 2012-04-25 Corrected the plist key to CFBundleIdentifier.
I've often wondered about how to do this without monkeying in Objective C. It's doable in (ugh) Applescript with some property list editing. Whimsical XKCD handler such that xkcd://627 behaves like http://xckd.com/627:
on open location uri
set delimiter to AppleScript's text item delimiters
set AppleScript's text item delimiters to "//"
set comic to text item 2 of uri
set page to "http://xkcd.com/" & comic
tell application "Safari"
activate
open location page
end tell
set AppleScript's text item delimiters to delimiter
end open location
Save as an Application rather than a Script. Open its info.plist and add
<key>CFBundleIdentifier</key>
<string>uk.co.zomo.xkcd-handler</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>XKCD helper</string>
<key>CFBundleURLSchemes</key>
<array>
<string>xkcd</string>
</array>
</dict>
</array>
To nudge OS X to notice changed a plist:
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -v -f ~/Library/Scripts/xkcd-handler.app
Links:
- http://applescript123.com/linktrigger/
- http://stackoverflow.com/questions/8981749/how-do-i-refresh-application-metadata-url-handlers-web-browsers-after-insta
- http://www.rubicode.com/Software/RCDefaultApp/
last updated: