I'm creating a launch daemon on my MacBook (with Monterrey installed) to bring back the battery percentage to the lock screen. I was able to craft the following command and run it in the terminal without any issue:
sudo defaults write /Library/Preferences/com.apple.loginwindow.plist LoginwindowText "Battery percentage: `pmset -g batt | perl -pe 's/.*?(\d+\%).*/$1/' | sed -n '2 p'`"
To automate the command (specifically to have it run every minute), I created a file in /Library/LaunchDaemons called com.thecoder.lockscreenbattery.plist with the following markup:
<?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.thecoder.lockscreenbattery</string>
<key>ProgramArguments</key>
<array>
<string>defaults write /Library/Preferences/com.apple.loginwindow.plist LoginwindowText "Battery percentage: `pmset -g batt | perl -pe 's/.*?(\d+\%).*/$1/' | sed -n '2 p'`"</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StartInterval</key>
<integer>60</integer>
</dict>
</plist>
Finally, to start the daemon, I ran the Terminal command sudo launchctl load /Library/LaunchDaemons/com.thecoder.lockscreenbattery.plist
(I also made sure that the file had execute permissions for the user, group, and others).
However, the command does not run like it's supposed to every minute. In fact, it only runs when I explicitly run it in the Terminal. Does anyone have any ideas for how I can continue troubleshooting this? Thank you so much in advance!