Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the icon of the user's Mac?

Using Objective-C and Cocoa, does anyone know how to get the icon for a user's computer (the one that shows under "Devices" and "Network" in Finder)? Not the harddisk icon, the actual one for a user's device. It ranges from a MacBook icon to the Mac Pro icon to a Windows blue screen of death monitor icon.

I've tried stuff along the following lines:

NSImage *icon = [[NSWorkspace sharedWorkspace] 
                  iconForFileType: NSFileTypeForHFSTypeCode(kComputerIcon)];

But that just returns the same icon all the time, obviously. I've also tried the iconForFile: method but I don't know of a file path to use as the parameter. Can anybody point me in the right direction?

like image 962
Alex B Avatar asked Sep 04 '09 23:09

Alex B


2 Answers

[NSImage imageNamed: NSImageNameComputer]

This will return the icon of the current computer

like image 155
cocoafan Avatar answered Sep 20 '22 20:09

cocoafan


Another place to look for icons:

/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources

You can create NSImage objects with the files in there like this:

[[NSImage alloc] initWithContentsOfFile:@"/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/com.apple.macbook-unibody.icns"];

It's probably not recommended to hard-code the value like that, however, since Apple may change the icons' locations. There is a file called IconsCore.h that contains many other constant values such as 'kToolbarDesktopFolderIcon' which can be used as follows:

[[NSWorkspace sharedWorkspace] iconForFileType: NSFileTypeForHFSTypeCode(kToolbarDesktopFolderIcon)];

I believe these constants only work in Snow Leopard, though.

like image 30
Alex B Avatar answered Sep 17 '22 20:09

Alex B