Creating an "Open With" Menu
Creating an "Open With" Menu
- Subject: Creating an "Open With" Menu
- From: Stephen Norum <email@hidden>
- Date: Thu, 24 Jun 2004 10:24:52 -0600
Hello,
I'd like to add an "Open With" menu similar to the Finder's Get Info
panel. The menu will be used to allow users to choose an external
editor for a specific file type - in this case, .wav files. I use
Launch Services to get an array of all applications it knows of, then I
check each app to see if it has the role of editor for the file (see
code below).
However, my list of apps does not match the Finder's list at all
(regardless of the role I specify). Applications such as "Microsoft
Word", "TextEdit", and "Mail" show up in the list of .wav editing
applications.
Any ideas on how to create a more accurate "Open With" menu?
Thanks,
Stephen Norum
email@hidden
http://ieee.usask.ca/members/snorum/
Current Code:
/*********************************************/
NSArray *urls;
CFURLRef waveFile;
Boolean canEdit;
NSEnumerator *enumerator;
CFURLRef currURL;
NSString *name;
// Get all application URLs
_LSCopyAllApplicationURLs(&urls);
// Make a CFURL to a .wav file
waveFile = CFURLCreateWithString(kCFAllocatorDefault, (CFStringRef)
@"file://localhost/Users/stephen/Desktop/wave.wav", NULL);
// Step through all applications
enumerator = [urls objectEnumerator];
while (currURL = (CFURLRef) [enumerator nextObject]) {
// Determine if the application can edit the file
LSCanURLAcceptURL (waveFile,
currURL,
kLSRolesEditor,
kLSAcceptDefault,
&canEdit);
// If the application can edit the file, add the app to the menu
if (canEdit) {
name = (NSString *) CFURLCreateStringByReplacingPercentEscapes
(kCFAllocatorDefault, CFURLGetString(currURL), CFSTR(""));
NSLog(@"Edit with: %@", [[name lastPathComponent]
stringByDeletingPathExtension]);
[name release];
}
}
/*********************************************/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.