检查是否在Mac OS X应用程序是present [英] Check if a Mac OS X application is present
本文介绍了检查是否在Mac OS X应用程序是present的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我记得有作为一个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.
我如何做到这一点?无论是可可,AppleScript的,或命令行是对我有用。
How do I do this? Either Cocoa, AppleScript, or command line are useful to me.
推荐答案
您应该使用<一个href=\"http://developer.apple.com/library/mac/#documentation/Carbon/Conceptual/LaunchServicesConcepts/\">Launch服务 要做到这一点,尤其是功能 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应用程序是present的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文