Ste*_*eod 9 macos cocoa applescript
我记得有一个Cocoa框架或AppleScript字典来检查计算机上的任何地方是否安装了具有特定名称的Application包.
我该怎么做呢?Cocoa,AppleScript或命令行对我都很有用.
Rob*_*ger 21
您应该使用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);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4151 次 |
最近记录: |