Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Buadhai

macrumors 65816
Original poster
Jan 15, 2018
1,121
436
Korat, Thailand
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 stupid 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:

Code:
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

Code:
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>

I have no idea where Lingon gets that massive path. Older Lingon generated plist files have something like this:
Code:
<key>PATH</key>
<string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Apple/usr/bin:/Applications/Wireshark.app/Contents/MacOS:/usr/local/sbin</string>

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.

Here's directory listing of an older script along with its plist file. This runs fine every day:
Code:
-rwxr-xr-x@ 1 mnewman staff 5472 May 2 2023 chaamyt.sh
-rw-r--r--@ 1 mnewman staff 891 May 2 2023 com.mgnewman.chaamyt.plist

And, here's the new one that doesn't run:
Code:
-rwxr-xr-x@ 1 mnewman staff 138 Nov 7 11:26 ldtest.sh
-rw-r--r--@ 1 mnewman staff 1195 Nov 7 11:48 com.mgnewman.ldtest.plist
[code]

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

Buadhai

macrumors 65816
Original poster
Jan 15, 2018
1,121
436
Korat, Thailand
Does it appear in launchctl list?
Yes. It's the first one in the list:

Code:
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

The other four are older and run reliably.

And:

Code:
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
 
Last edited:

Buadhai

macrumors 65816
Original poster
Jan 15, 2018
1,121
436
Korat, Thailand
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.)

I wonder what bug Apple fixed to enable newly saved plist files to work?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.