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 ? (, )