以编程方式获取有关 mac OS X 应用程序的信息

getting info about mac OS X application programmatically

我正在寻找 cocoa 为每个应用程序获取以下信息的框架:供应商名称、版本和完整的应用程序名称。

或者,我可以使用包含此信息的文件...我尝试在 /Application/(name).app/... 中搜索它,但我无法在特定位置找到它对于所有应用程序都是一样的。

应该在CFBundleName

下的info.plist

如果你进入 <application>/contents/info.plist,你会在那里找到它

来自  documentation:

CFBundleName (String - iOS, OS X) identifies the short name of the bundle. This name should be less than 16 characters long and be suitable for displaying in the menu bar and the app’s Info window. You can include this key in the InfoPlist.strings file of an appropriate .lproj subdirectory to provide localized values for it. If you localize this key, you should also include the key CFBundleDisplayName.

这是从所选应用程序的 Info.plist 获取版本的示例代码:

string GetAppVersion(string app)
{
    NSString *vlcFilePath = [NSString stringWithCString:app.c_str()];
    NSDictionary* infoDict = [[NSBundle bundleWithPath:vlcFilePath] infoDictionary];
    NSString* version = [infoDict objectForKey:@"CFBundleVersion"];
}
...
...
GetAppVersion("/Applications/Notes.app").c_str());