# How to disable sleep in MacOS while program is running?

**URL:** <https://discourse.processing.org/t/how-to-disable-sleep-in-macos-while-program-is-running/14384>\
**Category:** Coding Questions\
**Created:** [October 3, 2019, 3:23am UTC](https://discourse.processing.org/t/how-to-disable-sleep-in-macos-while-program-is-running/14384 "2019-10-03T03:23:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![spy](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@spy](https://discourse.processing.org/u/spy)\
**Post date:** [October 3, 2019, 3:23am UTC](https://discourse.processing.org/t/how-to-disable-sleep-in-macos-while-program-is-running/14384/1 "2019-10-03T03:23:15Z")

</div>

I created a digital full screen Clock in Processing. I also created a executable file to run it directly via double click. My OS is MacOS High Sierra. When I run it, my laptop goes to sleep after some time. I want to disable sleeping while my clock is running. Is there a programming way to do this.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [October 3, 2019, 4:40am UTC](https://discourse.processing.org/t/how-to-disable-sleep-in-macos-while-program-is-running/14384/2 "2019-10-03T04:40:36Z")

</div>

please use the system settings  
[https://www.youtube.com/watch?v=Shb0YJg2UPs](https://www.youtube.com/watch?v=Shb0YJg2UPs) info

---

<div class="post-metadata">

**Author:** ![spy](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@spy](https://discourse.processing.org/u/spy)\
**Post date:** [October 3, 2019, 5:58am UTC](https://discourse.processing.org/t/how-to-disable-sleep-in-macos-while-program-is-running/14384/3 "2019-10-03T05:58:56Z")

</div>

Thanks for replying but I want it to be done automatically. Like whenever program starts it disable sleep and when program ends normal status is enabled. Similar to like when we play video or watch movie we don’t have to disable sleep option. Something like that.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [October 3, 2019, 6:45am UTC](https://discourse.processing.org/t/how-to-disable-sleep-in-macos-while-program-is-running/14384/4 "2019-10-03T06:45:16Z")

</div>

i read about a JAVA trick  
so i put that into code but untested…

```auto
import java.awt.*;

  while (true) {
    try {
      Thread.sleep(1000); //1000 milliseconds is one second.
    } 
    catch(InterruptedException ex) {
      Thread.currentThread().interrupt();
    }
    Point mouseLoc = MouseInfo.getPointerInfo().getLocation();
    try {
      Robot bot = new Robot();
      bot.mouseMove(mouseLoc.x, mouseLoc.y);
      //println("you see me?");
    }
    catch (AWTException e) {
      e.printStackTrace();
    }
  }

```

but need to implement after testing ? like

```auto
import java.awt.*;

void setup() {
  size(200,200);
}

void draw() {
  background(200,200,0);
  rect(mouseX,mouseY,20,20);
  call_disable_sleep();
}

void call_disable_sleep() {
    if ( frameCount%100 == 0 ) {
    Point mouseLoc = MouseInfo.getPointerInfo().getLocation();
    try {
      Robot bot = new Robot();
      bot.mouseMove(mouseLoc.x, mouseLoc.y);
      println("you see me?");
    }
    catch (AWTException e) {
      e.printStackTrace();
    }
  }
}

```
