如何从NSApplication运行launchd agent / daemon?

时间:2014-09-10 18:49:45

标签: macos cocoa launchd

在我的NSApplication中,我有一个按钮。当我点击它时,我想启动/启动一个守护进程/代理。我该怎么办?我已经尝试过了:

- (void) runAgent {
    NSTask *task = [[NSTask alloc] init];
    task.launchPath = @"launchctl load /System/Library/LaunchAgents/com.mycompany.myagent.plist";
    [task setLaunchPath:@"/bin/sh"];
    [task launch];
}

没有成功......

1 个答案:

答案 0 :(得分:1)

    NSTask *task = [[NSTask alloc] init];
    [task setLaunchPath:@"/bin/launchctl"];
    [task setArguments:[NSArray arrayWithObjects:@"load",@"/System/Library/LaunchAgents/com.mycompany.myagent.plist", nil]];
    [task launch];