gpt4 book ai didi

cocoa - 检查 Mac OS X 应用程序是否存在

转载 作者:行者123 更新时间:2023-12-03 16:05:01 25 4
gpt4 key购买 nike

我记得有一个 Cocoa 框架或 AppleScript 字典来检查计算机上的任何位置是否安装了具有特定名称的应用程序包。

我该怎么做? Cocoa、AppleScript 或命令行对我来说都很有用。

最佳答案

您应该使用Launch Services为此,特别是函数 LSFindApplicationForInfo()

你像这样使用它:

#import <ApplicationServices/ApplicationServices.h>

CFURLRef appURL = NULL;
OSStatus result = LSFindApplicationForInfo (
kLSUnknownCreator, //creator codes are dead, so we don't care about it
CFSTR("com.apple.Safari"), //you can use the bundle ID here
NULL, //or the name of the app here (CFSTR("Safari.app"))
NULL, //this is used if you want an FSRef rather than a CFURLRef
&appURL
);
switch(result)
{
case noErr:
NSLog(@"the app's URL is: %@",appURL);
break;
case kLSApplicationNotFoundErr:
NSLog(@"app not found");
break;
default:
NSLog(@"an error occurred: %d",result);
break;
}

//the CFURLRef returned from the function is retained as per the docs so we must release it
if(appURL)
CFRelease(appURL);

关于cocoa - 检查 Mac OS X 应用程序是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5155528/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com