I created a command-line application for Mac OS without the GUI. This application is located at /usr/local/bin. And in some cases I need to execute Apple Script within that application. To do this, I create an NSTask and trying to run the following command:
NSTask *createTask = [[NSTask alloc] init];
createTask.launchPath = @"/bin/bash";
NSString *showAlert = [NSString stringWithFormat:@"/usr/bin/osascript -e 'tell application \"Finder\" to display alert \"My text.\"'"];
NSArray *arguments = [NSArray arrayWithObjects:@"-c",showAlert, nil];
createTask.arguments = arguments;
[createTask launch];
After it runs, nothing happens, only in logs appear the message:
Apr 14 15:35:15 Mac-mini kernel[0]: my-app: guarded fd exception: fd 0 code 0x2 guard 0x7fff8b9e12a8
Apr 14 15:35:15 Mac-mini com.apple.xpc.launchd[1] (com.apple.ReportCrash.Root[26852]): Endpoint has been activated through legacy launch(3) APIs. Please switch to XPC or bootstrap_check_in(): com.apple.ReportCrash.DirectoryService
Apr 14 15:35:15 Mac-mini diagnosticd[16097]: error evaluating process info - pid: 26851, punique: 26851
Apr 14 15:35:16 Mac-mini sandboxd[16099] ([26851]): my-app(26851) deny file-read-data /
But if you run this command directly from terminal, it is executed correctly. Please tell me, what am I doing wrong?