Skip to main content
edited body
Source Link
nohillside
  • 104.5k
  • 42
  • 222
  • 275

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.

https://apple.stackexchange.com/a/462512/501809

Instead of writing shell commands on terminal every time create a bash script.

#! /bin/zsh
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.

https://apple.stackexchange.com/a/462512/501809

Instead of writing shell commands on terminal every time create a bash script.

#!/bin/bash
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.

https://apple.stackexchange.com/a/462512/501809

removed redundant line
Source Link

Instead of writing shell commands on terminal every time create a bash script.

#! /bin/zsh
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, run it to toggle between settings just with a double click. I have posted the steps here.

https://apple.stackexchange.com/a/462512/501809

Instead of writing shell commands on terminal every time create a bash script.

#! /bin/zsh
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, run it to toggle between settings just with a double click. I have posted the steps here.

https://apple.stackexchange.com/a/462512/501809

Instead of writing shell commands on terminal every time create a bash script.

#! /bin/zsh
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.

https://apple.stackexchange.com/a/462512/501809

updated method to create bash script
Source Link

Instead of writing shell commands on terminal everytime,every time create an AppleScript Application anda bash script.

#! /bin/zsh
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, run it to toggle between settings just with a double click. I have posted the steps here.

https://apple.stackexchange.com/a/462512/501809

Instead of writing shell commands on terminal everytime, create an AppleScript Application and run it to toggle between settings just with a double click. I have posted the steps here.

https://apple.stackexchange.com/a/462512/501809

Instead of writing shell commands on terminal every time create a bash script.

#! /bin/zsh
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, run it to toggle between settings just with a double click. I have posted the steps here.

https://apple.stackexchange.com/a/462512/501809

Source Link
Loading