5

I'm trying to have launchd run a shell script when I join a new WiFi network. I've created this plist file (closely based on this SuperUser answer) at /Users/myname/Library/LaunchAgents/my.networkChangeListener.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" \
 "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<dict>
  <key>Label</key>
  <string>my.networkChangeListener</string>
  <key>LowPriorityIO</key>
  <true/>
  <key>ProgramArguments</key>
  <array>
<string>/Users/myname/bin/networkChangeListener/onNetworkChange.sh</string>
  </array>
  <key>WatchPaths</key>
  <array>
    <string>/etc/resolv.conf</string>
    <string>/Library/Preferences/SystemConfiguration/NetworkInterfaces.plist</string>
    <string>/Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
</dict>
</plist>

My user is the owner of the plist, and the group is "staff".

When I try to load the file by running launchctl load ~/Library/LaunchAgents/my.networkChangeListener.plist, I get an error saying "Invalid property list".

However, when I run plutil ~/Library/LaunchAgents/my.networkChangeListener.plist, it returns "OK"

What is the problem with my plist file? Is is something specific to launchd? I'm completely at a dead end for how to debug this.

9

The first few lines should be

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>

Your file (as well as the one in the linked answer) is missing the <plist version="1.0"> part.

  • 1
    Thank you! That solved the problem. It does seem like something plutil should have caught … but then, it also seems like something I should have caught in the oodles of times I read over the code looking for mismatched tags. – LiberalArtist Apr 16 '15 at 4:51
  • 2
    Just as a hint: OS X comes with xmllint, which is part of the OpenSource libxml. If you just want to validate xml, you could try this: endor-3:~ garex$ xmllint /tmp/my.networkChangeListener.plist /tmp/my.networkChangeListener.plist:21: parser error : Extra content at the end of the document </plist> ^ That showed that your plist tag was closed but not opened... – Garex Apr 16 '15 at 7:59
-1

A totally blank plist looks like this:

<?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/>
</plist>

I use PlistEdit Pro when having to do a lot of changes, as it is easy to make mistakes.

You must log in to answer this question.

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