Pretty cool command for MacOS:
caffeinate
If you open a terminal and enter that, itโll keep your Mac from going to sleep until you do a CTRL-C.
Can also control with some options:
caffeinate -u -t 10800
Thatโll prevent your Mac from sleeping for 10800 seconds, or three hours.