A MacOS script to turn off networking and put the Mac to sleep

I have no idea if I’ll keep using the script, but for the moment, this is a MacOS script (shell script) I named Turn-Off-Wifi-and-Run-Sleep.command:

time=2

networksetup -setairportpower en0 off
echo "Sleeping $time seconds ..."
sleep $time

osascript -e 'tell application "System Events" to sleep'

I saved this file to my desktop, made it executable with chmod, and then when I run it, it does what its name implies, turning off the Wi-Fi networking and then putting my Mac to sleep.

Note that when you run this script, it opens a MacOS Terminal window to show the result of the commands in the script.

I did this because the Mac had a weird error this morning this morning when I turned it on and it said it had run out of application memory while I was sleeping. ATM I don’t want the Mac working while I’m sleeping, so I wrote this script (though I don’t know how successful this approach will be).