i made a shutdown script for my mac way back when i had OSX 10.6, now with the advancements of OSX and its auto open feature the script is broke
The script works nicely, the machine shuts down in the given minutes supplied, but when the machine restarts the script is then rerun and asks for shutdown time again, so i have to force quit it.
Can anyone suggest how to get this to not reopen on startup?
thanks
property shutdown_time : date
on run
set response to display dialog "Please State Number of minutes until Shutdown?" with title "App" buttons {"Down!"} default answer "60" with icon path to resource "Time.icns" in bundle ("/Users/MAC Apps/Created Mac Apps")
set timer to (text returned of the response) as number
set shutdown_time to (current date) + (timer * minutes)
end run
on idle
if (shutdown_time < (current date)) then
tell application "System Events" to shut down
quit
end if
return 1
end idle
Just tried the below code, but when mac restarted the app opens again
Im not sure what you mean by:
property shutdown_time : date
on run
set response to display dialog "Please State Number of minutes until Shutdown?" with title "Down" buttons {"Down!"} default answer "60" with icon path to resource "Time.icns" in bundle ("/Users/MAC Apps/Created Mac Apps")
set timer to (text returned of the response) as number
set shutdown_time to (current date) + (timer * minutes)
end run
on idle
if (shutdown_time < (current date)) then
tell application "System Events"
ignoring application responses
shut down
end ignoring
end tell
quit
end if
return 1
end idle
I meant something like this otherwise I don’t know:
on idle
if (shutdown_time < (current date)) then
quit
end if
return 1
end idle
on quit
tell application "System Events"
ignoring application responses
shut down
end ignoring
end tell
continue quit
end quit
I’m just guessing because I’ve never shut down from an idle handler.
i assume its because as the application is shutting down the system is saving the applications states. As this application is actioning the shut down its state is saved as open, and thus reopens on restart.
property shutdown_time : date
on run
set response to display dialog "Please State Number of minutes until Shutdown?" with title "Down V2.0" buttons {"
Down!"} default answer "60" with icon path to resource "Time.icns" in bundle ("/Users/MAC Apps/Created Mac Apps")
set timer to (text returned of the response) as number
set shutdown_time to (current date) + (timer * minutes)
end run
on idle
if (shutdown_time < (current date)) then
quit
end if
return 1
end idle
on quit
tell application "System Events"
ignoring application responses
shut down
end ignoring
end tell
continue quit
end quit
do shell script "osascript -e \"tell application \\\"System Events\\\" to shut down\" 2>/dev/null"
Put the line above into a handler in a separate applet, and call it from inside of the ignoring responses block in your applet above. (Or just tell SystemEvents to shut down from within the other applet.) Good luck!
I tried to make a do shell script that I used to, but either I didn’t get it right, or it is impossible to send something that contains an osascript at least to the background.
Actually, the ignoring application block used to work. What it does is it doesn’t wait until the application gets a reply that it is shutting down. That’s what causes the application to stay alive until it gets a return which it never does. If you don;t wait for the reply, that’s what you want to do. I think that used to work. I’ll wait until tomorrow to test it.