Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

BossElijah

macrumors newbie
Original poster
Sep 1, 2022
1
0
Hello,

I am trying to caffeinate my computer during work hours + a bit more, so I want to do it from 8am to 7pm. I am able to manually do it by typing these commands in the terminal:
$ caffeinate
$ killall caffeinate

But I want to do that automatically.

I have something like this, but I don't know where to save it and what to do with it:
AppleScript:
-- If today is not weekend, and it is 8:00am, caffeinate.

on idle
    set currentTime to current date
    set eightAM to 8 * 60 * 60

    if the weekday of currentTime is not Saturday and the weekday of currentTime is not Sunday then
        if the time of currentTime is greater than eightAM and the time of currentTime is less than (eightAM + 60) then
                do shell script "caffeinate -t 39600 &"
        end if
    end if

    --only check once a minute
    return 60
end idle

Does anyone know how to do that?
Thanks, BossElijah
 
Last edited:
I do something similar using Lingon X to create a couple of daemons.

In the morning at 6:00 AM on Weekdays it runs
Code:
/bin/sh -c "caffeinate -u -t 2"
which wakes up the Mac.
Then at 6:00 PM every day it runs
Code:
/bin/sh -c "pmset displaysleepnow"
to put the display to sleep.

I have the Mac set to Never turn the display off in Energy Saver. I let the Mac run 24/7 because I have several automated tasks that run at night, like backups, etc. I'm just putting the display to sleep to save a little energy since I don't need the display on when I'm not at work.

Screen Shot 2022-09-01 at 9.55.54 AM.pngScreen Shot 2022-09-01 at 9.56.05 AM.png
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.