Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can I disable the sleep mode for a specific application so that my mac won't go on sleep until the app is closed?

share|improve this question
up vote 2 down vote accepted

If you have any interest in running shell script the following will work. Just set the "Display_Sleep_Time" and "System_Sleep_Time" as you want them to be along with the "App" you are choosing to prevent sleep on. By launching the script anytime you run your app your all sleep times will be turned to 0 preventing both your display and system from sleeping.


  • 10.5.x
  • 10.6.x
  • 10.7.4

NOTE: WARNING THIS SCRIPT DOES CONTAIN AN INTERNAL LOOP. You may prefer to utilize the following script inside a Daemon rather than use the internal loop the script provides. However, the same concept applies.




System_Sleep=$(pmset -g | grep " sleep" | awk '{print $2}')
Display_Sleep=$(pmset -g | grep " displaysleep" | awk '{print $2}')

while [[ ${watch} == "true" ]]; do

    watch_App=$(ps -A | grep "${App}.app" | grep -v grep | sed "s/.*${App}.*/${App}/")

    if [[ ${watch_App} == ${App} ]]; then

        if [[ ${System_Sleep} != "0" ]]; then
            pmset -a sleep 0
            System_Sleep=$(pmset -g | grep " sleep" | awk '{print $2}')

        if [[ ${Display_Sleep} != "0" ]]; then
            pmset -a displaysleep 0
            Display_Sleep=$(pmset -g | grep " displaysleep" | awk '{print $2}')

    elif [[ ${watch_App} != ${App} ]]; then

        if [[ ${System_Sleep} == "0" ]]; then
            pmset -a sleep ${System_Sleep_Time} > /dev/null 2>&1
            System_Sleep=$(pmset -g | grep " sleep" | awk '{print $2}')

        if [[ ${Display_Sleep} == "0" ]]; then
            pmset -a displaysleep ${Display_Sleep_Time} > /dev/null 2>&1
            Display_Sleep=$(pmset -g | grep " displaysleep" | awk '{print $2}')


        /usr/bin/logger -i An error has occured with


share|improve this answer
Could you add to the answer how to setup a deamon? – dierre Apr 19 '12 at 16:47
The simplest way might just be to download an app to help you through it. If you google 'download mac daemon tool free' you should find some helpful applications. They are generally very small and very simple to follow. Don't be afraid to try them. Remember though, it is not 100% necessary to do this. You can create a daemon without the aid of an application, or you can run this script as needed and if you are running it with root privileges it will function adequately. – E1Suave Apr 19 '12 at 17:18
Sorry for being a bit vague in regards to the downloads, but I am not 100% certain what the Stack Exchange policy is for listing specific applications to download. – E1Suave Apr 19 '12 at 17:20
1… found it. Tnx. Nice answer btw. – dierre Apr 19 '12 at 17:38

You could also add a line like this to a crontab:

* * * * * pgrep -x TextEdit && caffeinate -t 60

(Use EDITOR=nano crontab -e if you haven't changed $EDITOR and don't know how to use vi.)

caffeinate and pgrep were both added in Mountain Lion.

You can get a list of power assertions with pmset -g assertions. caffeinate or caffeinate -i should set PreventUserIdleSystemSleep to 1.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.