3

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

2

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.

0

Not that this will solve your problem (I have the same issue) but if you do a:

sudo launchctl load /Library/LaunchAgents/com.myfile.hostname.plist

It might work. It did for me. Maybe a clue as to what's happening. Maybe not. Let me know if you fix this issue. We're all in this together.

  • 1
    Would this be better as an edit to Graham's answer instead of setting apart? If you want to keep it apart, please elaborate on why sudo is needed in front of the command so that it helps spur discussion and perhaps helps the asker. – bmike Mar 6 '14 at 23:06
0

Pipes are a shell feature and launchd is not a shell. Put the command into a shell script instead and make your job call this script. Also get rid of the sudo in the script. If you need root privileges store the job definition in /Library/LaunchDaemons instead.

0

Removing the leading directories worked for me:

sudo launchctl start homebrew.mxcl.bind
-1

Remove the extension, it should work then.

launchctl start /Library/LaunchAgents/com.myfile.hostname

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .