My script looks like this:
#!/bin/sh
TITLE="Delete EVERYTHING and reinstall macOS"
HEADLINE="WARNING!! This will erase EVERYTHING!"
DECSCRIPTION1="This will erase ALL content and reinstall this mac."
DECSCRIPTION2="This will erase ALL content and reinstall this mac.
Are you sure you want to continue?"
DECSCRIPTION3="Make sure to connect a power supply!"
LOG="/private/tmp/install_mac_os.log"
echo "Erase and reinstall macOS" > $LOG
power=$(pmset -g batt | head -n 1 | cut -d \\' -f2)
echo "Power source: $power" > $LOG
HELPER=$(/Library/Application\\ Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -icon /private/tmp/InstallAssistant.icns -title "$TITLE" -heading "$HEADLINE" -alignHeading center -description "$DECSCRIPTION1" -lockHUD -button1 "Cancel" -button2 "REINSTALL" -cancelButton 1 -defaultButton 1)
if [[ $HELPER -eq 2 ]]; then
HELPER=$(/Library/Application\\ Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -icon /private/tmp/InstallAssistant.icns -title "$TITLE" -heading "$HEADLINE" -alignHeading center -description "$DECSCRIPTION2" -lockHUD -button1 "Cancel" -button2 "YES, DO IT" -cancelButton 1 -defaultButton 1)
if [[ $HELPER -eq 2 ]]; then
if [[ "$power" != "AC Power" ]]; then
HELPER=$(/Library/Application\\ Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -icon /private/tmp/InstallAssistant.icns -title "$TITLE" -heading "$HEADLINE" -alignHeading center -description "$DECSCRIPTION3" -lockHUD -button1 "Ok" -cancelButton 1 -defaultButton 1)
fi
echo "Ok, we reinstall" >> $LOG
else
echo "Abort"
exit 0
fi
else
echo "Abort"
exit 0
fi
open $LOG
echo "Setting: do not sleep for 3600 seconds (1 hour)" >> $LOG
# Do not sleep for 3600 seconds (1 hour)
caffeinate -u -d -t 3600 &
echo "Downloading installer..." >> $LOG
# Download installer
softwareupdate --fetch-full-installer >> $LOG
echo "Preparing wipe and reinstall..." >> $LOG
# Wipe and reinstall
/Applications/Install\\ macOS Monterey.app/Contents/Resources/startosinstall --eraseinstall --agreetolicense --newvolumename 'Macintosh HD' >> $LOG
It works just fine all the way up to the startosinstall command.
Instead of starting the installer command, it open the macOS Monterey installer
As if I rand only the app: /Applications/Install\\ macOS Monterey.app