Re: countdown to failiure
Re: countdown to failiure
- Subject: Re: countdown to failiure
- From: Sander Tekelenburg <email@hidden>
- Date: Mon, 12 Mar 2001 08:12:22 +0100
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
At 21:24 -0800 UTC, on 11/03/2001, Jason Ryant wrote:
>
hi all. i would like to build a simplistic script consisting of two
>
variables: 1. the current date and time and, 2. the date and time
>
specified by the user. what i would like to happen is for the user to
>
specify a date [lets say new year's] and for the script to tell the user
>
how much time there is until then. i whipped up something like this:
>
>
>
property UserDate : date
>
>
if UserDate = "" then
>
set UserDate to
>
display dialog "Please enter a date to track" default
>
answer ""
>
else
>
set TimeRemaning to ((UserDate) - (current date))
>
display dialog TimeRemaning
>
end if
>
>
>
any scripter can see that it won't work
I haven't tested, but I would say you're close. You're right to store the
chosen date in a property[*], and subtract that from the current date.
To catch the user's input, you need to change it to:
set UserDate to text returned of (display dialog "Please enter a date to
track" default answer "DD-MM-YY")
>
, but this is the jist of what i
>
want to happen. another question: is there a way to only use the shortened
>
date [eg. DDMMYY] insted of the full day of the week and month and year
>
written out?
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). Note that, in
the "default answer" of the script line above, I've placed a simple
suggestion for how to encourage the user to provide the date in the right
format. (Still, I believe the month is always returned by name - you may need
a routine to convert that to a number. I've seen such routines posted, but
I've never seen one I fully understand. My math sucks ;))
Perhaps you can get the right format by having your script first get "current
date", then have it look at how it is formatted, then use that format. Beware
though, that the further away the chosen date is, the bigger the chance the
user changes his Date & Time settings somewhere along the way...
So if you want foolproof, it'd probably be best to come up with some routine
that can recognise the Date & Time format, no matter what it's set to, and
then internally use your own format. (Might not be easy to achieve. Let us
know if you come up with something that works.)
>
what about just getting the current time?
get time string of (current date)
These may be useful too:
get day of (current date)
get month of (current date)
get year of (current date)
[*] 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.
HTH
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <
http://www.pgp.com>
iQA/AwUBOqx2zesywKfXgqKdEQLULwCfQ8QCX1LwTnQzCnu/8ZG5/ah63X4AnRoF
YYaPsdXaKgM3Jlvgw91muJac
=+6Ng
-----END PGP SIGNATURE-----
--
Sander Tekelenburg, <
mailto:email@hidden>
Web site at <
http://www.euronet.nl/~tekelenb/>
Mac user: "Macs only have 40 viruses, tops!"
PC user: "SEE! Not even the virus writers support Macs!"