Instead of writing shell commands on terminal every time create a bash script.
#! /bin/zshbash
sleepvar="$(pmset -g | grep SleepDisabled)"
sleepval="$(grep -c 0 <<< $sleepvar)"
if [ "$sleepval" -eq 1 ];
then
sudo pmset -b sleep 0; sudo pmset -b disablesleep 1
#echo "SleepDisabled set to 0, setting to 1 i.e. Disabling sleep"
else
sudo pmset -b sleep 1; sudo pmset -b disablesleep 0
#echo "SleepDisabled set to 1, setting to 0 i.e. Enabling sleep"
fi
save it as <filename>.command
, give it execution permissions using sudo chmod +x <filename>.command
after execution, use cmd+q
to close the terminal,
or to close automatically:
open terminal-> open "Terminal" menu -> Settings-> Shell -> open "when the shell exits" dropdown -> choose "close if the shell exited cleanly"
or you can alternatively create AppleScript Application for a more UI friendly experience, I have posted the steps here.