Estoy tratando de ejecutar un script de shell cuando me uno a una nueva red WiFi. Creé este archivo plist (muy basado en esta respuesta de Superusuario ) en /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>
Mi usuario es el propietario del plist y el grupo es "personal".
Cuando intento cargar el archivo ejecutando launchctl load ~/Library/LaunchAgents/my.networkChangeListener.plist
, aparece un error que dice "Lista de propiedades no válida".
Sin embargo, cuando ejecuto plutil ~/Library/LaunchAgents/my.networkChangeListener.plist
, devuelve "OK"
¿Cuál es el problema con mi archivo plist? ¿Es algo específico de launchd? Estoy completamente en un callejón sin salida sobre cómo depurar esto.
Las primeras líneas deben ser
<?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>
A su archivo (así como al de la respuesta vinculada) le falta la <plist version="1.0">
parte.
Un plist totalmente en blanco se ve así:
<?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>
Uso PlistEdit Pro cuando tengo que hacer muchos cambios, ya que es fácil cometer errores.
LiberalArtista
plutil
debería haberse detectado... pero también parece algo que debería haber detectado en las innumerables veces que leí el código en busca de etiquetas que no coincidían.Martín Allert
endor-3:~ garex$ xmllint /tmp/my.networkChangeListener.plist /tmp/my.networkChangeListener.plist:21: parser error : Extra content at the end of the document </plist> ^
eso mostró que su etiqueta plist estaba cerrada pero no abierta ...