5

I have an application Main.app and an application Helper.app within the Main.app/Library/LoginItems folder. The Main.app can be started by the user, and the user can then set Helper.app as login item. (using SMLoginItemSetEnabled()), this works perfectly. When the user sets the Helper.app as login item it is also launched.

However, it should also be possible to launch the Helper.app without setting it as a login item. I've tried to do this with

[[NSWorkspace sharedWorkspace] launchApplication: newPath];

which gives a lsboxd: Not allowing process to launch... error, and with

[NSTask launchedTaskWithLaunchPath:newPath arguments: [NSArray array]];

wich gives a deny forbidden-sandbox-reinit error. (presumably because the Helper.app is inside Main.app?)

newPath is found as follows:

NSMutableArray *pathComponents = [NSMutableArray arrayWithArray:[[[NSBundle mainBundle] bundlePath] pathComponents]];
[pathComponents addObject:@"Contents"];
[pathComponents addObject:@"Library"];
[pathComponents addObject:@"LoginItems"];
[pathComponents addObject:@"Helper.app"];
[pathComponents addObject:@"Contents"];
[pathComponents addObject:@"MacOS"];
[pathComponents addObject:@"Helper"];
NSString *newPath = [NSString pathWithComponents:pathComponents];

How can i fix this? :)

Thanks,

jeppeb
  • 528
  • 5
  • 12
  • http://stackoverflow.com/questions/12971549/mac-os-sandbox-launching-main-application-from-helper - it *may* be a signing issue that goes away once the app is in the app store – Anya Shenanigans Mar 12 '13 at 17:11
  • 1Password (with the 1Password Helper process) seems to be able to do it and they are sandboxed. I really wonder how they achieve it. – Remy Vanherweghem Sep 22 '13 at 18:19
  • I was also searchin for this and I just tried it the way you described it (except, that I kind of hardcoded the path, I really can't see why you do it the way you do) and it worked right away. I don't know what you're doing wrong (or if I am doing something wrong, which makes it work for me). – Sitses Oct 10 '13 at 23:22
  • have a look at http://stackoverflow.com/questions/12594380/how-to-launch-another-process-in-sandbox-on-mac – Parag Bafna Oct 21 '13 at 11:37
  • @RemyVanherweghem, we are using SMLoginItemSetEnabled in 1Password. – roustem Jan 07 '14 at 21:50

1 Answers1

0

You also can use NSTask and launchctl. Example Or you can use NSTask and bash script. Example:

#Run Menu
if [ $(ps -u $USERNAME | grep -v grep | grep -m1 '/Library/Menu/Menu.app/Contents/MacOS/Menu' | awk '{print $5}') ]; then 
    echo "Menu already  running";
else 
    echo "Menu not  running"
    if [ $(users $USERNAME ) == $USERNAME ]; then
        echo "User logined"
        echo "running menu for user $USERNAME"
        sudo -u $USERNAME /Library/Menu/Menu.app/Contents/MacOS/Menu&
    else
        echo "User not logined"
    fi
fi
user1502383
  • 323
  • 1
  • 5