The goal is to set machine's network name with the ipaddress of this machine.
I have created a plist file and put it into /Library/Launchagents/. For debugging reason I used the command "launctl start".
Here is my 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.myfile.hostname</string>
<key>ProgramArguments</key>
<array>
<string>/usr/sbin/ipconfig</string>
<string>getifaddr</string>
<string>en0</string>
<string>|</string>
<string>/usr/bin/tr</string>
<string>-d</string>
<string>'.'</string>
<string>|</string>
<string>sudo</string>
<string>/usr/sbin/scutil</string>
<string>--set</string>
<string>LocalHostName</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/tmp/AlTest1.err</string>
<key>StandardOutPath</key>
<string>/tmp/AlTest1.out</string>
</dict>
</plist>
Then I use:
launchctl start /Library/LaunchAgents/com.myfile.hostname.plist
and get the error:
launchctl start error: No such process
As the error is not explaining what exactly is wrong with that file Im struggling to find the reason. The command itself on the command work fine. If this is the wrong section for this question please advice.
Thanks in advance
Best Answer
Try using the launchctl command:
launchctl load /Library/LaunchAgents/com.myfile.hostname.plist
This will load the job ticket rather than start a named job.
I am not sure pipes are permitted within a launchd job ticket list of arguments. Using them requires the argument to be passed to a shell for interpretation and this may not happen. Consider passing the command directly to
/bin/sh
as a single argument.