Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'An AppleScript to generate a timed shutdown' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An AppleScript to generate a timed shutdown
Authored by: cougar718 on Feb 17, '04 05:14:51PM
Hey all, Not bad Steve. I decided to clean up your code a bit. It now uses a different method than using delay or sleep which is... Sets the scheduled date to the current date + Number entered * 60 (Converts the number entered into minutes) Then on idle, tests if the current date is greater than or equal to the scheduled date. Like I said, good job and thanks for the contribution. Hey all if you want to use this version, simply paste it into Script Editor and save as an application making sure Stay Open is checked since this script utilizes the on idle event. Cheers,

--Created by StevenT 
--Modified by cougar

-- How many seconds before we remove the shutdown notice? 
property pIntTimeout : 3
property pIntTimeAmount : ""
property pDateGoal : ""

on run
	set pDateGoal to ""
	set blnValid to false
	repeat until blnValid
		set recDialog to display dialog "Enter in how many minutes until the computer shuts down?" default answer "" buttons {"Cancel", "Ok"} default button 2
		try
			set pIntTimeAmount to text returned of recDialog as integer
			if (pIntTimeAmount > 0) then
				set blnValid to true
			else
				error
			end if
		on error
			display dialog "Invalid Number - Numbers must be integers and greater than 0" buttons {"Ok"} default button 1
		end try
	end repeat
	
	set strMinute to " minute"
	if (pIntTimeAmount > 1) then set strMinute to strMinute & "s"
	display dialog "The computer will shutdown in " & pIntTimeAmount & strMinute & "!" buttons {"Ok"} default button 1 giving up after pIntTimeout
	set pDateGoal to (current date) + (pIntTimeAmount * 60)
end run

on idle
	try
		if ((current date) ? pDateGoal) then
			tell application "Finder" to shut down
		end if
	end try
end idle

---
Rick alias cougar

[ Reply to This | # ]

Have it remember your last shutdown delay
Authored by: ngb on Feb 18, '04 02:14:49AM
In the display dialog line, change default answer "" to display dialog pIntTimeAmount, and the script will display your last timeout as the default. Whenever the script changes the value of a property, it remembers the new value next time it is launched. The complete line is below.

set recDialog to display dialog "Enter in how many minutes until the computer shuts down?" ¬
     default answer pIntTimeAmount buttons {"Cancel", "Ok"} default button 2


[ Reply to This | # ]
An AppleScript to generate a timed shutdown
Authored by: cougar718 on Mar 08, '04 05:29:26PM
Hey all, Seems that the >= character was not carried over correctly. Should be...

on idle
	try
		if ((current date) >= pDateGoal) then
			tell application "Finder" to shut down
		end if
	end try
end idle

---
Rick alias cougar

[ Reply to This | # ]

An AppleScript to generate a timed shutdown [Final Version]
Authored by: cougar718 on Apr 15, '04 02:34:24PM
Here is the final version of this script. It was brought to my attention that there was a critical component of the code missing it is fixed now. Simply compile and Save as an Application and make sure "Stay Open" is checked.

--Created by StevenT 
--Modified by cougar

-- How many seconds before we remove the shutdown notice? 
property pIntTimeout : 3
property pIntTimeAmount : ""
property pDateGoal : ""

on run
	set pDateGoal to ""
	set blnValid to false
	repeat until blnValid
		set recDialog to display dialog "Enter in how many minutes until the computer shuts down?" default answer pIntTimeAmount buttons {"Cancel", "Ok"} default button 2
		try
			set pIntTimeAmount to text returned of recDialog as integer
			if (pIntTimeAmount > 0) then
				set blnValid to true
			else
				error
			end if
		on error
			display dialog "Invalid Number - Numbers must be integers and greater than 0" buttons {"Ok"} default button 1
		end try
	end repeat
	
	set strMinute to " minute"
	if (pIntTimeAmount > 1) then set strMinute to strMinute & "s"
	display dialog "The computer will shutdown in " & pIntTimeAmount & strMinute & "!" buttons {"Ok"} default button 1 giving up after pIntTimeout
	set pDateGoal to (current date) + (pIntTimeAmount * 60)
end run

on idle
	try
		if ((current date) >= pDateGoal) then
			tell application "Finder" to shut down
		end if
	end try
	return 1
end idle

---
Rick alias cougar

[ Reply to This | # ]

An AppleScript to generate a timed shutdown
Authored by: pgk on Oct 03, '05 10:33:48PM

For some reason, this script isn't working for me. The dialog boxes display as they should and the fields seem to accept entries okay. But my computer is still not shutting down. Any ideas? Btw, if it matters, I'm running OSX 10.4.2 on a 15" Titanium PB. Thanks!



[ Reply to This | # ]
An AppleScript to generate a timed shutdown (Final Version)
Authored by: pgk on Oct 03, '05 10:36:17PM

To clarify, I'm running the "Final Version" of the script. Thanks.



[ Reply to This | # ]
An AppleScript to generate a timed shutdown (Final Version)
Authored by: pgk on Oct 03, '05 11:51:47PM

Nevermind. It's working now. (I may have failed to select the "Stay Open" option when I first saved the script.)



[ Reply to This | # ]