I would like to achieve simple thing but struggling for the whole day. :(
I made a simple macOS app. In AppDelegate, applicationDidFinishLaunching, I would like to execute a helper program which is bundled together inside the app.
https://github.com/hkjlee109/objc-helper-example
But I am getting an error.
Load failed: 5: Input/output error
Try running `launchctl bootstrap` as root for richer errors.
Here's what I did: 0. From
- I've a target called "helper-agent" which is a commandline application.
- For "helper-agent" application, I've added "com.example.helper.agent.plist" file.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.example.helper.agent</string>
<key>BundleProgram</key>
<string>Contents/Resources/helper-agent</string>
<key>MachServices</key>
<dict>
<key>com.example.helper.agent</key>
<true/>
</dict>
</dict>
</plist>
And I've added two things for "Build phase" of main application.
- Copy Bundle Resources: Copy "helper-agent" application to "Contents/Library/LaunchAgents"
- Copy Files: Copy "com.example.helper.agent.plist" to "Contents/Library/LaunchAgents"
Lastly, in AppDelegate, I am using below code to launch the helper.
NSTask* task = [NSTask new];
task.launchPath = @"/bin/launchctl";
task.arguments = @[@"load", @"com.example.helper.agent.plist"];
[task launch];
[task waitUntilExit];
I would be appreciated for any piece of advices or suggestions. Thanks!