Skip to content

Prevent Mac sleep

ให้ติดตั้ง Python version 3

bash

brew install python3

เพิ่ม Library pyautogui

bash

pip3 install pyautogui

สร้าง script preventSleep.py

python

from time import sleep
import pyautogui
import random
 
## prevent sleep max x hours
maxHour=2
 
## keep moving mouse every x seconds
waitingBeforeMoveMouse=10
 
count=0
while count<((3600/waitingBeforeMoveMouse)*maxHour):
x=random.randint(1,1000)
y=random.randint(1,1000)
pyautogui.moveTo(x, y)
print(x)
print(y)
sleep(waitingBeforeMoveMouse)
count+=1

Run script preventSleep.py

bash

python3 preventSleep.py