Skip to content

Instantly share code, notes, and snippets.

@sankim
sankim / sleep-timer.scpt
Last active March 5, 2024 09:55 — forked from fbender/sleep-timer.scpt
AppleScript to put your Mac to sleep after X minutes, fading out the system volume shortly before sleeping. Can be turned into an app via the "Export" feature of the AppleScript Editor.
-- written by Florian Bender, 2015
-- forked and edited by San Kim, 2019
-- based on work by Michael Wyszomierski <https://wysz.com/wyszdom/2009/06/simple-sleep-timer-with-applescript/>
-- license: Public Domain / CC0 <http://creativecommons.org/publicdomain/zero/1.0/>
tell application "System Events"
set fadeTime to 10 -- time in seconds for fade change
-- display alert "Volume: " & volumeValue & ", Delta: " & fadeChange
display dialog "Sleep time (min):" default answer "60"
delay ((text returned of the result) * 60 - 30)
display notification "Going to sleep in 30 sec" with title "Sleep Timer"