On 4 Apr 2011, at 23:38, "Gerriet M. Denkmann" <gerr...@mdenkmann.de> wrote:
> I want to make certain files to be opended by default by my own editor. > These files might contain all sort of file extentions. > In Finder.app I could do: File â∫‚ Always open with..., but I want to do this > programmatically. > > I guess I have to add a 'usro' Resource (see: > <http://sutes.co.uk/2009/09/creator-codes-are-not-replaced.html>). > > But I have great difficulties finding and understanding the relevant > documentation. > > Also: I cannot find the 'usro' string in any header file (and Xcode does not > give any information either). > > So, does anybody has some code snippets to share which can read, modify, > write a 'usro' resource? > The code below seems to work - but looks like a really bad hack. (All error handling removed for brevity). Maybe someone has a better solution? + (NSString *)openerForFsRef: (FSRef *)fsRef; { NSString *opener = nil; SInt16 file = FSOpenResFile( fsRef, fsRdPerm ); // The total number of unique resource types in the current resource file. ResourceCount typesCount = Count1Types(); for( short typeIndex = 1; typeIndex <= typesCount; typeIndex++ ) // iterate over all types { ResType theType; Get1IndType( &theType, typeIndex ); // The total number of resources of a given type in the current resource file. ResourceCount rsrcCount = Count1Resources( theType ); for( int rsrcIndex = 1; rsrcIndex <= rsrcCount; rsrcIndex++ ) // iterate over resources for current type { Handle rsrcHandle = Get1IndResource( theType, rsrcIndex ); if ( theType == NSHFSTypeCodeFromFileType( @"'usro'" ) ) { // this probably is a bad hack - what if there are more than 255 chars in the opener string? const unsigned char *bytes = *rsrcHandle; NSUInteger lenn = bytes[0] - 1; NSData *daa = [ NSData dataWithBytes: &bytes[4] length: lenn ]; opener = [ [ NSString alloc ] initWithData: daa encoding: NSUTF8StringEncoding ]; [ opener autorelease ]; }; }; }; CloseResFile( file ); return opener; } _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com