I am new to lanuchctl. On my Mac running macos-ventura, I have created several plists that all load fine but will not run (neither by launchctl start nor by specifying RunAtLoad in the plist.
(Thanks to Martin R for pointing me to the log directory).
It turns out that the issue seems to be with trying to use /usr/local/bin (and other /usr/local/* folders) that have been mounted to external volumes for space reasons.
To get to the root of the matter, I have created the following plist stored at ~/Library/LaunchAgents/it_works.plist. It does indeed load my script, with some interesting results.
The plist is:
<?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>/Users/dennis/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/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/bin:/homebrew/bin:/homebrew/Cellar/php@7.4/7.4.29/bin</string>
</dict>
<key>Label</key><string>local.itWorks</string>
<key>ProgramArguments</key>
<array>
<string>/Users/dennis/bin/itWorks</string>
</array>
<key>WorkingDirectory</key><string>/Users/dennis</string>
<key>StandardOutPath</key> <string>/Users/dennis/local.itWorks.stdout</string>
<key>StandardErrorPath</key><string>/Users/dennis/local.itWorks.stderr</string>
<key>RunAtLoad</key><true/>
<key>Debug</key><false/>
</dict>
</plist>
The script merely outputs some environmental information:
#!/usr/bin/env ksh
LOG=local.itWorks.hmmm...
exec 1>>$LOG
exec 2>&1
cd /Users/dennis
echo "it works."
echo HOME=$HOME
echo PATH=$PATH
echo '<?php printf("realpath(/usr/local/bin) returns %s\n", realpath("/usr/local/bin"));'|php
set -x
ls -ld /usr/local/bin
ls -l /usr/local/bin
ls -l /usr/local/bin/*
ls -l /Volumes/Satechi.SSD.M2
ls -l /Volumes/Satechi.SSD.m2/usrlocal
ls -l /Volumes/Satechi.SSD.M2/usrlocal/bin
ls -l /Volumes/Satechi.SSD.M2/usrlocal/bin/*
echo ''
After execution, the resultant output file ~/local.itWorks.hmmm... contains
it works.
HOME=/Users/dennis
PATH=/Users/dennis/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/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/bin:/homebrew/bin:/homebrew/Cellar/php@7.4/7.4.29/bin
realpath(/usr/local/bin) returns /Volumes/Satechi.SSD.M2/usrlocal/bin
+ ls -ld /usr/local/bin
lrwxr-xr-x 1 root wheel 36 Apr 28 2022 /usr/local/bin -> /Volumes/Satechi.SSD.M2/usrlocal/bin
+ ls -l /usr/local/bin
lrwxr-xr-x 1 root wheel 36 Apr 28 2022 /usr/local/bin -> /Volumes/Satechi.SSD.M2/usrlocal/bin
+ ls -l '/usr/local/bin/*'
ls: /usr/local/bin/*: No such file or directory
+ ls -l /Volumes/Satechi.SSD.M2
ls: /Volumes/Satechi.SSD.M2: Operation not permitted
total 0
+ ls -l /Volumes/Satechi.SSD.m2/usrlocal
ls: /Volumes/Satechi.SSD.m2/usrlocal: Operation not permitted
total 0
+ ls -l /Volumes/Satechi.SSD.M2/usrlocal/bin
ls: /Volumes/Satechi.SSD.M2/usrlocal/bin: Operation not permitted
total 0
+ ls -l '/Volumes/Satechi.SSD.M2/usrlocal/bin/*'
ls: /Volumes/Satechi.SSD.M2/usrlocal/bin/*: No such file or directory
+ echo ''
As we can see, use of our nonstandard /usr/local/bin (and friends) is completely fouled, not working anything like manual execution, whose output starts like this:
it works.
HOME=/Users/dennis
PATH=/Users/dennis/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/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/bin:/homebrew/bin:/homebrew/Cellar/php@7.4/7.4.29/bin
realpath(/usr/local/bin) returns /Volumes/Satechi.SSD.M2/usrlocal/bin
+ ls -ld /usr/local/bin
lrwxr-xr-x 1 root wheel 36 Apr 28 2022 /usr/local/bin -> /Volumes/Satechi.SSD.M2/usrlocal/bin
+ ls -l /usr/local/bin
lrwxr-xr-x 1 root wheel 36 Apr 28 2022 /usr/local/bin -> /Volumes/Satechi.SSD.M2/usrlocal/bin
+ ls -l /usr/local/bin/HandBrakeCLI /usr/local/bin/addGPSfromSRT /usr/local/bin/adddate /usr/local/bin/all-systems /usr/local/bin/appcontrol /usr/local/bin/archiveUserLogs.php /usr/local/bin/atjobs
As soon as I add anything in the plist referencing an external volume (even by name /Volumes/VolumeName/folder/whatever), launchd just gives me a "not found" in the log file.
Hopefully there is a way to reference external volumes in scripts that launchd runs, else I'm pretty much out of business - and I'll have to drop back to crontab stuff.
Any help here? I'll be happy to clarify or provide more information.
/usr/localis just supporting info..), however, putting the solution in the question is not recommended. You can answer your own question (and get rep for it). – Andy Griffiths Jul 18 '23 at 16:57