:o
hello all,
i new to this forum, and to applescript… so help is very much appreciate…
i have a mac that is always on [a server] i want to it to launch an application everyday at 7:30 am and close it at 7:30pm… i really don’t know how to do it and i guess its very simple… the this is that i just want it to run once and for all not everyday run the script…
this is what i came up with but the thing in this is that i need to rerun this code everyday… please check it out…
repeat
set the theDate to the current date
if (time string of theDate) = "7:30:00 am" then
tell application "QuickMail Pro"
launch
end tell
end if
if (time string of theDate) = "7:30:00 pm" then
tell application "QuickMail Pro"
quit
set the theDate to the current date
end tell
end if
end repeat
You could save this as stay-open app, and add it to your login-items:
global delayTime
set delayTime to 5 * 60 --> eg, check every 5 minutes
on idle
if delayTime is not (5 * 60) then
quit app "QuickMail Pro"
quit
end if
set c to current date
if (hours of c) is 7 and (minutes of c) is 30 then
launch app "QuickMail Pro"
set delayTime to 12 * 3600 --> come after 12 hours
end if
return delayTime
end idle
NOTE: Or, if you have more tasks, you could use iCal for all your schedule-applescript needs.
thanks jj for the help,
but can u explain for me a bit what does delayTime exactly do? and how is it used :s why do u put it 5*60 and the 12 * 3600?? andhow does it afect the code?
psycho-ed
The “idle” handler will be executed every “delayTime” seconds. The first time, we will check every 5 minutes (5 * 60 seconds) if it’s time to launch the app. When it is, we will increase “delayTime” to 12 hours (12 * 3600 seconds). So, the next time the “idle” is executed (12 hours later), we will simply quit and blah.
10x for the help guys,
but jj’s code is not working i tried it
and what iss with the sleep thing?? does this mean if the cpu stops working then the apple script terminates?
psycho-ed
I did not know that if the machine sleeps a applescript wouldn’t run. I figured [especially if they were running] they would still work.
On the other hand, if you have a cron set up and the mac has gone to sleep, the system won’t run them. That said, there are alternative solutions which prevent this from happening though …
As our server [itself] is monitorless, we don’t allow the hard drive, or the screensaver, energy saver, etc to run.
That’s why OS X included the option to wake-up computers at scheduled times (check the calendar option in the Energy Saver panel), or why utilities like iBeeZz exist (or existed).
What is your OS, psycho-ed? (maybe the “hours of” and “minutes of” thing is not working in your system → as this post is in the Mac OS forum)
Cron was deprecated in Tiger in favour of launchd, which has an Anacron-like “run at next available opportunity” behaviour (as seen in the periodic logs).
The error must be a very large amount of time in the first delay: it checks every five minutes, good enough to skip the minute 30. Simply adjust where you see “5 * 60” to “50” (for example), so it won’t skip minute 30.
10x again jj,
but i have thaught of that earlier and i have adjusted the 5*60 to just 5 and yet it did not work…
hope u can help more,
regards
psycho-ed
i’ve checked it out, what is not working is the “on idle” please check it out and advise me what to do…
please check the code on ur machine on any other appication, u’ll c that it is not working even if u set the time delay to 1…
thanks for the help,
psycho-ed