I have stay open script running on a Mac Mini for the sole purpose of cycling through URLs, like a kiosk. I’d like to use the Mac’s Energy Saver abilities to turn it off at 6pm. However, it won’t work because the script is running.
I was thinking of using an if statement with “Current Date” , ripping out the time as a string and comparing if it’s less than 6:00PM to continue, else quit the script. Is this completely asinine?
Any suggestions on the most efficient way to alter my script?
Adding this to your idle routine should do it… the dialog can be removed, but helps with testing:
on idle
set the_time to (time of the (current date)) / 3600
if the_time > 18 then
display dialog "Quitting Now..." buttons {"OK"} default button 1 giving up after 2
tell me to quit
end if
return 2
end idle
Thanks Peter, but I’m having trouble getting it to work. I tried “tell me to quit”, “quit me”, and neither work. The script tries to quit, but gets stuck. Can you take a look at what I have and see if anything sticks out as being incorrect.
property theSites : {"http://www.macscripter.net", "http://www.apple.com", "http://www.google.com"}
script showSites
repeat with theURL in theSites
tell application "Safari"
activate
open location theURL
delay 15
try
close window 2
end try
end tell
end repeat
end script
on idle
set the_time to (time of the (current date)) / 3600
if the_time > 18 then
--display dialog "Quitting Now..." buttons {"OK"} default button 1 giving up after 2
quit application "Safari"
quit application "SafariShowShutDown"
else
tell showSites to run
end if
return 15
end idle
I’m really trying to stay away from using System Events and keystrokes because that would cause my previous scripts to error out all the time. This script works great, except for the shutting down part. which is key for me using the Energy Saver option. If either app is running, the Mac won’t shut down. Any help is greatly appreciated!
Thanks - slimjim
Now all you need to do is set up the laptop to shut down at 6:01 in the system preferences (Under energy saver/schedule… on tiger) and it should stop working.
I don’t know what “SafariShowShutDown” is or does, but both of these scripts worked - your stay open (as slightly modified) and a non-stay open below - quitting Safari and (effectively) quitting themselves.
Peter B.
property theSites : {"http://www.macscripter.net", "http://www.apple.com", "http://www.google.com"}
script showSites
repeat with theURL in theSites
tell application "Safari"
activate
open location theURL
delay 15
try
close window 2
end try
end tell
end repeat
end script
on idle
set the_time to (time of the (current date)) / 3600
if the_time > 18 then
--display dialog "Quitting Now..." buttons {"OK"} default button 1 giving up after 2
quit application "Safari"
--quit application "SafariShowShutDown"
tell me to quit
else
tell showSites to run
end if
return 2
end idle
property theSites : {"http://www.macscripter.net", "http://www.apple.com", "http://www.google.com"}
repeat
set the_time to (time of the (current date)) / 3600
if the_time < 18 then
repeat with theURL in theSites
tell application "Safari"
activate
open location theURL
delay 15
try
close window 2
end try
end tell
end repeat
else
quit application "Safari"
--quit application "SafariShowShutDown"
error number -128
end if
end repeat
Peter -
“SafariShowShutDown” is the name of the StayOpen application where this script lives. I plopped this in there when “tell me to quit” didn’t work for me. This is what I want to quit after it quits Safari.
So you’re telling me that I don’t need to use “on idle”?
I assumed from your first post that since you were using a stay open script, you already had some sort of ‘on idle’ routine. After seeing your script, I realized it didn’t even need to be stay open.
Often, there is more than one way to skin a cat. The two scripts use about the same percentage of CPU, so it’s sort of a toss up.
No idea why ‘tell me to quit’ isn’t working for you, I’m afraid. It’s conceivable using the same idle interval as the delay length may have been giving problems, but I really can’t say.
Peter -
Thanks for your help. I got it working with the aid of your second script. Also, I deselected the preference in Safari to notify when closing multiple windows. That may have been what was hanging me up. Thanks again for your guidance.
Now between the hours of 6:05pm and 7:45am, I’m saving the environment…four Mac Minis at a time.