I'm attempting to write my first LaunchDaemon: I think it's pretty simple and meets all the requirements, but it won't run.
The file is at /Library/LaunchDaemons/com.noah.supertest.plist
Ideally, it should be running ls
and writing the output to ~/test.txt
. But nothing is ever written to the file.
I restarted the machine thinking that might do it, but nothing.
<?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.noah.supertest</string>
<key>ProgramArguments</key>
<array>
<string>ls</string>
<string>></string>
<string>~/test.txt</string>
</array>
<key>KeepAlive</key>
<true/>
<key>StartInterval</key>
<integer>10</integer>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Permissions are set as root:wheel
Best Answer
You made several errors:
Here is a working plist:
You have to create the file ~/test.txt first before running the launch agent.
Then start the launch agent with
sudo launchctl [subcommand [arguments ...]]
and check the result: