I’ve been wondering why the stay-open script that I made to make previous versions of iTunes quit playing after some time would not work on 4.5. The problem happens only if the idling time goes past midnight. The idler just doesn’t work. At other times, it works perfectly. What gives?
Would appreciate if someone could take a look at my script below and see if there’s anything wrong with it. It used to work with previous iTunes version but not now. Is the problem with this script or is it with iTunes 4.5?
If the trouble is with the script, any suggestion how to redo the time arithmetic to make it work past midnight? I’ve tried several tricks but none has worked yet.
on run
set currDate to current date
copy time of currDate to startCounter
copy my get_lengthPlayTime() to lengthPlaytime
set timeiTunesStopPlay to (startCounter + lengthPlaytime * minutes)
end run
on idle
copy my get_theTime() to presentTime
my makeiTunesQuit(presentTime)
return idlePeriod
end idle
to get_theTime()
set currDate to current date
set presentTime to (time of currDate)
return presentTime
end get_theTime
to get_lengthPlayTime()
display dialog "How many minutes before iTunes should quit? " default answer userPlayTime
set lengthPlaytime to text returned of the result as integer
return (lengthPlaytime)
end get_lengthPlayTime
to makeiTunesQuit(presentTime)
if presentTime is greater than timeiTunesStopPlay then
tell application “iTunes”
stop
end tell
else
return
end if
end makeiTunesQuit
Glad to help. Yes it will work. The basic idea is that time resets to 0 at midnight. So if you compare time anytime from 30 minutes before midnight to 30 minutes after that time, then that time will never be less than the time after. It resets at midnight. On the other hand, date is continuous.
Your advise worked like a charm. My script is working perfectly now thanks to your suggestion to use date arithmetic instead of time arithmetic. I was already fiddling with it but never got around to solving the problem until I decided to try BBS and found the likes of you…such big help.
This kind of confuses me though because I used the time arithmetic with older versions of iTunes and my script worked then. But anyway, I have buried that time arithmetic in the past already. Your solution is hella better.
Thanks a lot. Would you like to try downloading and using iTunes Music Alarm Clock 3.5.2? It’s shareware but for you it’s a great pleasure to offer it free. Don’t worry a thing about it. You saved me a ton of time that I can now devote to learning AppleScript Studio programming. Your contribution is already in that version.
Chow. May great helpers like you prosper in this world!
Thanks for the offer. I already made several iTunes scripts and alarm scripts from when my alarm broke. The alarm script has snooze and is easy to modify.