Launching the Mac OS X Helper Application (LoginItem) from the Main Application

I have a Main.app application and a Helper.app application in the Main.app/Library/LoginItems folder. The Main.app user can be started by the user, and the user can set Helper.app as an input element. (using SMLoginItemSetEnabled ()), this works fine. When the user sets Helper.app as an input element, it also starts.

However, it should also be possible to run Helper.app without setting it as an input element. I tried to do this with

[[NSWorkspace sharedWorkspace] launchApplication: newPath];

which gives lsboxd: does not allow the process to start ... an error, but with

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

which gives a ban on a sandbox ban. (presumably because Helper.app is inside Main.app?)

newPath is defined 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? :)

Thank,

+5
source share
1 answer

You can also 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
0
source

All Articles