Re: countdown to failiure
Re: countdown to failiure
- Subject: Re: countdown to failiure
- From: Chris Nebel <email@hidden>
- Date: Mon, 12 Mar 2001 11:28:25 -0800
- Organization: Apple Computer, Inc.
Sander Tekelenburg wrote:
>
This should point you to the main problem: what date notation to use. It will
>
have to be the same as the user's Date & Time setting. This is one area where
>
scripters typically behave like webdeezignerz: they only look at how it works
>
on their Mac and forget about possible differences on others (which is fine
>
for your local scripts, but not for to be distributed ones).
Actually, the user's format is exactly what you want in this case. You're
getting input from the user, and they're presumably conditioned to type in dates
as they've got them formatted on their system. The date-to-string routines that
AppleScript uses to convert 'date "string"' into a date are fairly smart about
long vs. short formats and missing pieces. Don't try to dictate a format to the
user and you'll be fine. (If you were going to try to parse a date string
yourself, then you'd need to be aware of the varying date formats, but you don't
need to do that for this script.)
>
The only thing is that this would make it a throw-away script - how will
>
the user be able to change the property, unless by opening and recompiling
>
the script? If you want that to be easier, it might work better to store it
>
in a prefs file instead. The user could then trash the prefs file, which
>
would trigger an error in your script that you can use to respond with the
>
initial dialog asking for a date.
>
>
Another, more elegant, but perhaps a bit harder to implement, way to use a
>
prefs file is to make it user editable. For an example you might want to take
>
a look at my app "Disk Watcher" (see
>
<http://www.euronet.nl/~tekelenb/software/diskwatcher/index.html>), which
>
uses a UNIX-like prefs file that's user editable. Not terribly hard, but it
>
requires a decent understanding of how to work with read/write commands.
A much easier solution, both for you and the user, is to have another button
that lets them set the date. Try something like this:
on run
if UserDate is "" then SetUserDate()
repeat
set TimeRemaining to UserDate - (current date)
display dialog SecondsToString(TimeRemaining) & " until " & UserDate
,
buttons {"Another Date", "OK"} default button "OK"
if button returned of the result is "Another Date" then
SetUserDate()
else
exit repeat
end if
end repeat
end run
The implementation of SetUserDate and SecondsToString is left as an exercise for
the reader. :)
--Chris Nebel
AppleScript Engineering