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

lynkynpark86

macrumors 6502
Original poster
I got bored yesterday, so I created a small but powerful timer in applescript. You enter a time in minutes, and then you can do all of the following automatically when the timer runs out: Sleep, Shutdown, Restart, Run Application, and UNIX command. I have tested them all, and it works great. I find it useful for overnight downloads, DVD rips, watching DVDs, playing music, or anything else that would need a sleep timer. Here's the code:
Code:
set timeMinutes to text returned of (display dialog "Enter time to delay in minutes" default button 2 default answer "")
set timeSeconds to (timeMinutes * 60)

display dialog "Choose an action to delay" buttons {"Sleep, Shutdown, or Reboot", "Run Application", "UNIX Command"}
set the button_pressed to the button returned of the result
if the button_pressed is "Sleep, Shutdown, or Reboot" then
	display dialog "Select one" buttons {"Sleep", "Shutdown", "Reboot"}
	set the button_pressed to the button returned of the result
	if the button_pressed is "Sleep" then
		delay timeSeconds
		tell application "Finder" to sleep
	else if the button_pressed is "Shutdown" then
		delay timeSeconds
		tell application "Finder" to shut down
	else
		delay timeSeconds
		tell application "Finder" to restart
	end if
else if the button_pressed is "Run Application" then
	set varApp to text returned of (display dialog "Enter the Application to run" default answer "")
	delay timeSeconds
	activate application varApp
else
	set varCommand to text returned of (display dialog "Enter the Command to do" default answer "")
	delay timeSeconds
	do shell script varCommand
end if
I am not responsible if someone out there with a good lawyer finds a way to use this to destroy their computer. I hope to soon release a clock-based version (sleep at 9:30, not in 120 minutes). Happy sleep-timing!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.