Preventing sleep during imaging

macboy
Contributor

I am setting up prestage enrollment and it seems to be working rather nice. However, when I add all the packages I want to install in my policy it takes some time to install them all. During this time the Mac will go to sleep and requires me to wake it up to finish. Does anyone know of a way to prevent sleep for the Mac until it is completely done? I have tries putting in the caffeinate command in one of the scripts but it doesn't seem to work. I have also tried running it in the end of a policy in the Files and Processes. Any ideas on how to get it to stay awake? Thank you.

3 REPLIES 3

Look
Valued Contributor III

Not sure if it will work during imaging (but it should). I have a script I add to big policies to caffeinate the machine for several hours (it defaults to 3 but you can pass it anything up to 48).
You should be able to add it as a before script, although you can't pass parameters during imaging so you might need to change the default if 3 hours is insufficient for your needs.
Basically it caffeinates the machine and then divorces the process so it stays caffienated even after the script or imaging or any other event that calls it finishes. The disaply will still sleed though (you could change it to -sid if you wanted that prevented as well).

#!/bin/sh

declare -i LIVE_TIME
LIVE_TIME=10800
if [ "$4" ] && [ "$4" -lt "49" ]; then
LIVE_TIME=$4*3600
fi
echo Machine will not sleep for $LIVE_TIME seconds.
( caffeinate -si -t $LIVE_TIME ) &
disown
exit

Chris_Hafner
Valued Contributor II

Admittedly, I've gotten lazy and used to AutoCasperNBI. Creating NBIs has never been easier and they don't go to sleep.

Chris_Hafner
Valued Contributor II

That is, unless this is a non-OS imaging enrollment (i.e. thin-imaging). In which case, just never mind my NBI comments.