I found this script to shutdown my mac when i choose a certain time, it is not my script but i understand how it works:
property shutdown_time : date
on run
set response to display dialog “Number of minutes until Shutdown?” default answer “60”
set timer to (text returned of the response) as number
set shutdown_time to (current date) + (timer * minutes)
display dialog "This computer will shut down at: " & shutdown_time as string
end run
on idle
if (shutdown_time < (current date)) then
tell application “Finder” to activate
tell application “System Events”
tell process “Finder”
click menu item “Shut Down.” of menu 1 of menu bar 1
end tell
end tell
tell me to quit
end if
return 0
end idle
However, i cannot get it to run, the dialog box takes the number of minutes created, it then sets the time fine, and the time string is returned in the next dialog box. I Click ok and wait the 1 minute entered, but the system does not shut down…
tell application "System Events"
set allProcesses to name of every application process whose name is not NAMEOFYOURAPPLICATIONPROCESS
repeat with i in allProcesses
try
do shell script "killall " & i
end try
end repeat
shut down
end tell
Though, I think it isn’t save. I, personally wouldn’t, use it, because it also force quits for example the processes loginwindow, mdworker, SystemUIServer, etc. But. no password is needed!
I Am Playing with simple commands at present, but cannot understand what is going on here:
property shutdown_time : date
on run
set response to display dialog "Please State Number of minutes until Shutdown?" with title "Shutdown" buttons {"Shutdown", "Cancel"} default button 2 default answer "60" with icon path to resource "Time.icns" in bundle ("/Users/jbird/Documents/MAC Apps/Created Mac Apps")
set timer to (text returned of the response) as number
set shutdown_time to (current date) + (timer * minutes)
display dialog "This computer will Shutdown at: " & shutdown_time as string with title "Shutdown" buttons {"Close"} default button 1 with icon path to resource "Time.icns" in bundle ("/Users/jbird/Documents/MAC Apps/Created Mac Apps")
end run
on idle
if (shutdown_time < (current date)) then
tell application "System Events" to shut down
tell application "iTunes" to quit
tell application "Safari" to quit
tell application "QuickTime Player" to quit
tell application "Thunderbird" to quit
tell application "UnRarX" to quit
tell application "TextEdit" to quit
tell application "iGetter" to quit
tell application "Preview" to quit
tell application "VLC" to quit
quit
end if
return 1
end idle
It keeps returning : Cannot Make Date into Type number, date or text.