Apple’s Worldwide Developers Conference to kick off June 10 at 10 a.m. PDT with Keynote address

The Keynote will be available to stream on apple.com, the Apple Developer app, the Apple TV app, and the Apple YouTube channel. On-demand playback will be available after the conclusion of the stream.

You can make a difference in the Apple Support Community!

When you sign up with your Apple ID, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Developer Forums relocated!

Need help with Apple Developer tools and technologies? Want to share information with other developers and Apple engineers? Visit Developer Forums at Apple.

Launchd runs old scripts, but won't run new scripts

I'm sure this is something simple. Be that as it may, I can't figure it out.


I've been writing simple shell scripts for years that I run via launchd plist files created with Lingon. Generally that works fine unless I do something dumb which is not all that rare.


However, after installing Sonoma, I can't get launchd to run new scripts on either an old Intel iMac or a newer M1 MBA.

To keep things simple, I've written a very brief shell script along with a very minimal launchd plist:


Sellotape:bin mnewman$ cat ldtest.sh
#!/bin/bash
# shell script to test launchd
now=$(date +%Y-%m-%d-%H%M)
echo $now " hello" >> /users/mnewman/public/ldtest.log
exit 0


Sellotape:LaunchAgents mnewman$ cat com.mgnewman.ldtest.plist
<?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>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/usr/local/sbin:/opt/local/bin</string>
</dict>
<key>Label</key>
<string>com.mgnewman.ldtest</string>
<key>ProgramArguments</key>
<array>
<string>/Users/mnewman/bin/ldtest.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/Users/mnewman/public/error.log</string>
<key>StandardOutPath</key>
<string>/Users/mnewman/public/output.log</string>
<key>StartCalendarInterval</key>
<array>
<dict>
<key>Hour</key>
<integer>11</integer>
<key>Minute</key>
<integer>40</integer>
</dict>
</array>
</dict>
</plist>




If I run the script from the command line it works as expected. However, launchd will not run it. I've sat there and watched the console scroll by at the time it should be running and there's nothing.


Lingon's test facility reports no errors and there's nothing in Lingon's log file.


Sellotape:public mnewman$ launchctl list | grep mgnewman
-    0    com.mgnewman.ldtest
-    0    com.mgnewman.deljpeg
-    0    com.mgnewman.volume
-    0    com.mgnewman.ip
-    0    com.mgnewman.chaamyt


It's the first one. The other four are older and run reliably.


And:


Sellotape:public mnewman$ launchctl print-disabled gui/501/com.mgnewman.* | grep mgnewman
        "com.mgnewman.deljpeg" => enabled
        "com.mgnewman.ldtest" => enabled
        "com.mgnewman.mailtest" => disabled
        "com.mgnewman.volume" => enabled
        "com.mgnewman.chaamyt" => enabled


It's the second one, so enabled for launchd.


So, what silly thing have I done this time? I'm sure it's something simple, but beyond my feeble brain to uncover.


MacBook Air 13″, macOS 14.0

Posted on Nov 7, 2023 10:35 PM

Reply

Similar questions

3 replies

Nov 8, 2023 3:32 PM in response to Buadhai

Thank you. Updating to 14.1.1 fixed this problem on both machines. Oddly, I have Automatic Updates enabled on both machines but never received any notice that an update to 14.0 was available. (I just checked my wife's M1 iMac and saw that the System Settings icon in the Dock is badged to indicate that an update is available.)


Any idea what bug Apple fixed to allow newly saved plist files to work?

Launchd runs old scripts, but won't run new scripts

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.