Sending message from Terminal does not work when the Mac is sleeping I have a script that LaunchControl runs in the middle of the night to back up my database and send a message that it has been done. The message is sent as follows:

osascript -e 'tell application "Messages" to send "backup completed" to buddy "admin"'


I am running macOS Mojave. This works fine if I test it during the day, but in the middle of the night it, the message is not sent even thought the backup occurs. Presumably it has something to do with the fact that my machine is asleep. How do I fix this?
The Mac must be powered on to run your script. Only a few Apple specific processes are allowed to run via PowerNap.

pmset

You can use pmset to schedule your Mac to wake in the middle of the night.


  pmset allows you to schedule system sleep, shutdown, wakeup and/or power on. "schedule" is for setting up one-time power events, and "repeat" is for setting up daily/weekly power on and power off events. Note that you may only have one pair of repeating events scheduled - a "power on" event and a "power off" event. For sleep cycling applications, pmset can schedule a "relative" wakeup or poweron to occur in seconds from the end of system sleep/shutdown, but this event cannot be cancelled and is inherently imprecise.
  
  
  type - one of sleep, wake, poweron, shutdown, wakeorpoweron 
  date/time - "MM/dd/yy HH:mm:ss" (in 24 hour format; must be in quotes) 
  time - HH:mm:ss 
  weekdays - a subset of MTWRFSU ("M" and "MTWRF" are valid strings) 
  owner - a string describing the person or program who is scheduling this one-time power event (optional)
  


See How to Power On Your Mac at a Specific Date and Time for more details, including a graphical approach, and alternative tools.