From: Adam Gardner Date: 2009-02-21T08:06:07+09:00 Subject: Re: RubyCocoa and Mac System Icons Tom Medhurst wrote: > Hi There, > > I am trying to create an NSImage which contains the system kComputer > icon. Unfortunately RubyCocoa can't resolve kComputer or > use :kComputer or it's header value 'root'.. I have tried the > following: > > 1. NSWorkspace.sharedWorkspace.iconForFileType(NSFileTypeForHFSTypeCode > (:root)) > 2. NSWorkspace.sharedWorkspace.iconForFileType(NSFileTypeForHFSTypeCode > (:kComputer)) > 3. NSWorkspace.sharedWorkspace.iconForFileType(NSFileTypeForHFSTypeCode > (kComputer)) > 4. NSWorkspace.sharedWorkspace.iconForFileType(NSFileTypeForHFSTypeCode > (NSNumber.numberWithUnsignedLong('root'))) > > 5. NSWorkspace.sharedWorkspace.iconForFileType(:root) > 6. NSWorkspace.sharedWorkspace.iconForFileType(:kComputer) > 7. NSWorkspace.sharedWorkspace.iconForFileType(kComputer) > etc... > > Has anybody got this to work in RubyCocoa? > Many Thanks > *Tom Medhurst* First off, since in Ruby all constants begin with a capital letter, all the constants like kSuchAndSuch morph into OSX::KSuchAndSuch. Second of all, where on earth is kComputer defined? I can't find it documented *anywhere*; in particular, it's not in this list: http://developer.apple.com/documentation/Carbon/Reference/IconServices/Reference/reference.html#//apple_ref/doc/uid/TP30000239-CH4g-TPXREF130 Third, it seems to me that the iconForFileType method of NSWorkspace takes a string representing either a filename extension or a HFS file type. So if anything of these is going to work, it'd be: OSX::NSWorkspace.sharedWorkspace.iconForFileType('root') which does, in fact, return an NSImage instance for me. Of course, I get an NSImage with every string I've tried, including the empty string - I haven't tried drawing it on screen to see if it's the one you want, since I don't have anywhere to draw it to, as it were. But it should be a good place for you to start. -- Posted via http://www.ruby-forum.com/.