检查是否存在 Mac OS X 应用程序 [英] Check if a Mac OS X application is present
本文介绍了检查是否存在 Mac OS X 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我记得有一个 Cocoa 框架或 AppleScript 字典来检查是否在计算机的任何位置安装了具有特定名称的应用程序包.
I recall there being a Cocoa framework or AppleScript dictionary to check if an Application bundle with a specific name is installed at all, anywhere on the computer.
我该怎么做?Cocoa、AppleScript 或命令行对我都很有用.
How do I do this? Either Cocoa, AppleScript, or command line are useful to me.
推荐答案
你应该使用 启动服务来执行此操作,特别是函数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);
这篇关于检查是否存在 Mac OS X 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文