Matt Gemmell

CHANGER is available now!

An action-thriller novel — book 1 in the KESTREL series.

★★★★★ — Amazon

Cocoa source code: GetNetApps

source 1 min read

I’ve released a new piece of Cocoa source code today, called GetNetApps. It’s a little app which shows how to pass in a string containing a URL protocol (that’s the beginning part of an URL, which tells what kind of URL it is - like “http:” or “mailto:” or “ftp:” or whatever), and find the default application the user has chosen to handle URLs of that protocol. It actually finds the localised display name of the app, the full (root-relative) path to the app, and also its icon (the big 128x128 one).

It’s useful if you have an app which, say, launches an URL in the default browser, and you want to add an NSToolbarItem for that function. The nicest thing to do would be to make it such that the icon for that NSToolbarItem was the icon for the user’s default web browser - this source code lets you do that easily (in that case by using the “http:” protocol, of course).

Strictly speaking, it’s not entirely Cocoa, since it uses LaunchServices, but you don’t need to #include any additional headers or add any frameworks. The code is very simple too. So go and download it (53k, StuffIt), and get coding!