在查找程序中,用户可以右键单击/“打开方式”,查看可用于打开文件的应用程序列表。
如何以编程方式获取此应用程序列表?
ObjC或Python首选,但也很好奇是否有一个公开此功能的命令行实用程序。
答案 0 :(得分:1)
NSArray *applicationURLs = CFBridgingRelease(LSCopyApplicationURLsForURL((__bridge CFURLRef)fileURL, kLSRolesAll));
NSLog(@"applicationURLs %@", applicationURLs);
//输出
applicationURLs (
"file:///Applications/calibre.app/",
"file:///Applications/Archiver.app/",
"file:///Applications/Pacifist.app/",
"file:///System/Library/CoreServices/Archive%20Utility.app/"
)
默认应用:
CFURLRef defaultApplicationForURL = NULL;
LSGetApplicationForURL((__bridge CFURLRef)fileURL, kLSRolesAll, NULL, &defaultApplicationForURL);
NSLog(@"deafultApplicationForURL %@", defaultApplicationForURL);
//输出
deafultApplicationForURL file:///System/Library/CoreServices/Archive%20Utility.app/