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

liiiziiika

macrumors newbie
Original poster
Dec 22, 2023
3
0
Hello everyone. I need help please... I have macbook air M1 that was upgraded to sonoma but I am loosing my mind as I can't find energy saver option or any resembeling option that would allow me to just set a simple sleep timer to turn off my computer after 60 min (even if there is music or some other app playing in the background)

I have tried to use terminal (with a command: sudo shutdown -h +60) and it seemes to work - but I had to also change in settings that my computer doesn't lock itself before the commad run (otherwise the command wouldn't run). Which is fine but if I go somewhere it means I have to change the settings again and again. I am sure macbook air did have sleep timer before sonoma. As far as i know it seems I don't have the energy saver and schedule option. I am very sad that sleep timer isn't given to us on a platter as it would make an overall experience even better.

Thank you in advance
 

bogdanw

macrumors 603
Mar 10, 2009
6,152
3,049
Hypnotize "is open-source, and is published under a 'Creative Commons Attribution Non-Commercial License'"
http://www.mednotes.net/about/portfolio/programmer/
The downloaded app no longer works, but you can use the AppleScript from inside the app and save it as an app, this is a modified version for 60 minutes:

AppleScript:
activate

set x to {"Finder", "Applet", "Hypnotize"}

set y to 60
set z to y * 60

repeat
    display dialog "Shutting down in " & y & " minutes..." as string with title "Hypnotize" buttons {"Restart Timer", "Stop Timer"} default button 1 cancel button 2 giving up after z
    
    if button returned of result is "Restart Timer" then
        set z to y * 60
        
    else if button returned of result is "Stop Timer" then
        return false
        
    else if gave up of result is true then
        tell application "System Events"
            key code 53
            set t to name of every process whose background only is false
        end tell
        
        repeat with u in t
            if u is not in x then
                close every window of application u
                quit application u
            end if
        end repeat
        
        tell application "System Events"
            shut down
        end tell
        
        activate
        return false
        
    end if
end repeat
 
  • Like
Reactions: liiiziiika

liiiziiika

macrumors newbie
Original poster
Dec 22, 2023
3
0
Yes, replace shut down with sleep:
tell application "System Events"
sleep
end tell
So i tried to run the code in applescript and after a few minutes it gave message: "Script Editor got an error: The document can’t be closed while the script is running." I am not sure of what document is it refering too... I had only had safari open (because of netflix).

PS.: I also want to point out (for any readers in the future) that I had to close all of the programs that are not native to apple, because they would disturbe the run.
 

MajorFubar

macrumors 68020
Oct 27, 2021
2,175
3,830
Lancashire UK
Along the same lines I wanted my Mac Studio to shut off every night at 00:10 just in case I forget. Sometimes I can go days without using it, and it's crazy to leave it just sitting there wasting electricity when my utilities bill is already £200 a month. Not too long ago this was an easy task in Settings. I got there in the end thanks to help on here, but once again...another mildly-advanced feature needlessly removed by Apple in their ongoing 'dumbing-down' iOS-ification of the once-great MacOS.

It seems inevitable they will at some point remove the ability for us to make Aggregate or Multioutput virtual audio devices in Audio Midi Setup (because iOS can't do it), which is an absolutely critical function in my home studio. And at that point I'll just f'k off back to Windows where literally everything else is just better, not least the basic ability to cut and paste files between different folders.
 
  • Like
Reactions: liiiziiika

bogdanw

macrumors 603
Mar 10, 2009
6,152
3,049
So i tried to run the code in applescript and after a few minutes it gave message: "Script Editor got an error: The document can’t be closed while the script is running." I am not sure of what document is it refering too... I had only had safari open (because of netflix).
It’s referring to the script, it tries to close itself.
Save the script as an app https://support.apple.com/guide/script-editor/scpedt1072/mac
I had more time to test in Sonoma and I put together a version that works better, based on “AppleScript that Quits all running apps at once” by @Jayson A https://forums.macrumors.com/thread...ll-running-apps-at-once.2379603/post-31939592

AppleScript:
-- Credits:
-- Original code by Hypnotize http://www.mednotes.net/about/portfolio/programmer/; Hypnotize is open-source, and is published under a 'Creative Commons Attribution Non-Commercial License'
-- "AppleScript that Quits all running apps at once" code by Jayson A https://forums.macrumors.com/threads/i-wrote-an-applescript-that-quits-all-running-apps-at-once.2379603/post-31939592

activate
set y to 1
set z to y * 60
repeat
    display dialog "Shutting down in " & y & " minutes..." as string with title "Hypnotize" buttons {"Restart Timer", "Stop Timer"} default button 1 cancel button 2 giving up after z
    if button returned of result is "Restart Timer" then
        set z to y * 60
    else if button returned of result is "Stop Timer" then
        return false
    else if gave up of result is true then
        try
            tell application "System Events"
                set listOfProcesses to (name of every process where background only is false)
                set noFinder to listOfProcesses's (items 2 thru -1)
            end tell
            repeat with x in noFinder
                quit application x
            end repeat
        end try
        tell application "System Events"
            shut down
        end tell
        activate
        return false
    end if
end repeat

The code above is for 1 minute, open Script Editor, copy-paste the code, save it as an app, run the app (double-click). At first run, it will ask for permission to run System Events, grant that permission.

After that, you can open Script Editor again and from the File – Recent menu open the script inside the saved app and modify 1 to the number of minutes you want. So, from set y to 1 for 1 minute to set y to 60 for 60 minutes.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.