Code to check for an external application without breaking the sandbox

I am creating an application and I would like to check if my computer has installed the application (Example.app, com.example.test) and will be able to send the application to the Mac App Store.

I tried several things, for example:

NSString *script = @"try\r tell application \"Finder\" to get application file id \"com.example.test\"\r set appExists to true\r on error\r set appExists to false\r end try";
NSAppleEventDescriptor *result = [self executeScript:script];
return [result booleanValue];

This works fine, but I read that Apple does not allow temporary exceptions for the Finder in the rights file to provide a secure application.

I also tried something similar, but avoid using the Finder:

NSString *script = @"set appID to id of application \"Example\"\r set msg to exists application id appID\r tell application \"Example\" to quit\r return msg";
NSAppleEventDescriptor *result = [self executeScript:script];
return [result booleanValue];

This only works if the user has an application, if not, it will offer a dialog with a request for the location of the application. (and shows an example icon in the dock for a few milliseconds)

I also tried several hacker solutions like:

NSTask *task = [NSTask new];
[task setLaunchPath:@"/bin/bash"];
[task setArguments:@[@"if ls /Applications/Example.app >/dev/null 2>&1; then echo FOUND; else echo NOT FOUND; fi"]];
[task launch];
[task waitUntilExit];

int status = [task terminationStatus];

if (status == 0)
    NSLog(@"Task succeeded.");
else
    NSLog(@"Task failed.");

, , ( , ).

(checkbox), , , , , , , . , . ( , )

:

  • , ( ) ?
  • Finder , Apple ? (, )

+4
2

NSWorkspace?:

NSURL *appURL = [[NSWorkspace sharedWorkspace] 
               URLForApplicationWithBundleIdentifier:@"com.example.test"];

nil, , , Launch Services " " , , NSURL. (Launch Services, CoreServices ), , ). Launch Services , , , .

AppleScript, , , , Finder , : Launch Services, .

+7

( Automation WWDC 2012 ), NSUserScriptTask. , NSUserAppleScriptTask, AppleScript . script XPC script osascript. , , script, NSApplicationScriptsDirectory, ~/Library/Application Scripts/<bundle-id>/

, , , script , . , NSAppleScript, , NSUserScriptTask, ().

0

All Articles