Skip to content

launchd – MacOS – Scheduled Launch Daemon Not Running

  • by
Spread the love

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/ 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" "">
<plist version="1.0">

    <string>defaults write /Library/Preferences/ LoginwindowText "Battery percentage: `pmset -g batt | perl -pe 's/.*?(d+%).*/$1/' | sed -n '2 p'`"</string>



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!

Leave a Reply

Your email address will not be published. Required fields are marked *