For some reason I cannot get this to work with a .plist
I am not sure what goes wrong… here are a couple of infos that should help:
1: If I follow the README.md and name it ‘mac2mqtt’ the file will not run when ./mac2mqtt
. Terminal returns:
./mac2mqtt: line 1: package: command not found
./mac2mqtt: line 3: syntax error near unexpected token `newline’
./mac2mqtt: line 3: `import (’
If I then change the mac2mqtt to mac2mqtt.go and instead of ./mac2mqtt.go
execute: go run .
everything works:
2021/10/18 19:10:17 Started
2021/10/18 19:10:19 Connected to MQTT
2021/10/18 19:10:19 Sending ‘true’ to topic: mac2mqtt/Glenns-MacBook-Pro/status/alive
Everything good, but… I want to run it all the time on boot…
Now this is my .plist (where user is username on macOS):
<?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.user.mac2mqtt</string>
<key>ProgramArguments</key>
<array>
<string>/Users/user/mac2mqtt/mac2mqtt.go</string>
</array>
<key>WorkingDirectory</key>
<string>/Users/user/mac2mqtt/</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/Users/user/mac2mqtt/myjob.log</string>
<key>StandardErrorPath</key>
<string>/Users/user/mac2mqtt/myjob.log</string>
<key>Debug</key>
<true/>
</dict>
</plist>
If I then load it by:
launchctl load /Library/LaunchDaemons/com.user.mac2mqtt.plist
I again get the same return as in first scenario.
Is there an obvious mistake somewhere I cannot find?