I'm trying to use Launchd to run the following shell script:
#!/bin/sh
## wait for sunset, touch file
NIGHTTIME='/Users/mnewman/Documents/webcam/nighttime.txt'
sunwait civ down 14.98N 102.09E
touch "$NIGHTTIME"
"sunwait" is an executable which runs in the background and waits for sunset/sunrise and then quits. In this case I'm setting it to wait until civilian twilight sunset at my geographic location.
If I run this script from the command line it works fine. If I run it using Launchd, the touch command runs before sunwait finishes. I need for sunwait to finish before executing the next line. How do I do this?
touchruns beforesunwaitreturns, rather thansunwaitfailing and exiting early in this case?exec >/tmp/wait-for-night.log 2>&1; set -xat the beginning of your script and looking at the contents of/tmp/wait-for-night.logafter reproducing this behavior.NIGHTTIME; all-uppercase names are, by convention, reserved for environment variables and builtins, such that using lowercase names for shell variables prevents unintentional conflicts).