2

I wrote a Mac app that turns Desktop icons visible/invisible. I use NSTask to run a terminal command to reset the Finder:

- (void)killFinder
{
    NSTask *killFinderTask = [[NSTask alloc]init];
    NSArray *killFinderArray = [NSArray arrayWithObjects:@"Finder", nil];
    [killFinderTask setLaunchPath:@"/usr/bin/killall"];
    [killFinderTask setArguments:killFinderArray];
    [killFinderTask launch];
    [killFinderTask waitUntilExit];
}

Before turning on Sandboxing, it runs alright. When I turn on Sandboxing, a message in console said:

killall: warning: kill -TERM 46676: Operation not permitted

My app still runs but the result is not correct. The part which reset the Finder is not run. How do I circumvent this issue so that I can still use Sandboxing but the task is still run?

mahal tertin
  • 3,239
  • 24
  • 41
Standstill
  • 399
  • 4
  • 17
  • 1
    I don't think you can. At least I hope you can't, else it's not much of a sandbox. – trojanfoe Jul 02 '14 at 14:26
  • 1
    Your app can't reach out of sandbox, that is why you can't. Even if you achieve this your app will be rejected. – modusCell Jul 02 '14 at 14:54
  • Are you submitting your app to Mac app store ? – GoodSp33d Jul 03 '14 at 06:08
  • I wish to but it seems like it is not possible. So I can only distribute outside Mac App Store. – Standstill Jul 04 '14 at 12:45
  • By the way, this was never a good way to restart the Finder. You could have sent the same signal that `killall` would programmatically using `kill()`. You could use `NSRunningApplication` to `terminate` it. You could use Apple Script to quit it. No need to invoke an external program. Although these are also going to be restricted by the sandbox, they are at least more likely to have an official entitlement to enable it. – Ken Thomases Sep 29 '18 at 02:23

1 Answers1

1

Use NSUserScriptTask to run the Script.

The script file must be placed (by the user) in the NSApplicationScriptsDirectory to be run outside of the Sandbox.

pkamb
  • 33,281
  • 23
  • 160
  • 191