Re: Fun with coercing to string
Re: Fun with coercing to string
- Subject: Re: Fun with coercing to string
- From: Richard 23 <email@hidden>
- Date: Tue, 20 Feb 2001 23:08:15 -0800
>
WHAT WORKS:
>
month of (current date) --> February
>
>
set ThisMonth to month of (current date)
>
display dialog ThisMonth
>
--displays a dialog box with the text 'feb'
>
>
WHAT DOESN'T WORK:
>
set ThisMonth to month of (current date)
>
display dialog "We are in the month of " & ThisMonth
>
--Can't make February into a string
Display dialog and indeed choose from list both are auto-coerce-to-string
challenged. What you are seeing is the month's 4-character type code.
Unfortunately the coercion you are expecting ("WHAT DOESN'T WORK" does,
just not until Mac OS 8.6) didn't arrive until AppleScript 1.3.6:
Convert constant to string: This feature allows you to receive
Apple event data and convert it to a string for more flexible use
of the information. For example, the constant for the month of the
current date OSAX can now be converted to a string with a standard
coercion.
Yet in 9.0.4 I don't seem to be able to coerce the current date value to
a list of properties like the reference you quote. Odd.
>
According to my AppleScript reference tables current date command is
>
coercible to a list of its properties.
You may have misread this. I see coercible to a single-item list which
is kind of a cheat. Anything can be made into a single-item list by
wrapping braces around it. Who decided to call that a coercion?
For real fun though you should try my CoerceToString handler.
It takes advantage of the fact that AppleScript taunts you with error
messages claiming it can't coerce a value to a string by displaying
the value it can't coerce...as a string!
I would appreciate it if you would contact me offlist to let me know
if you have success with it. I have used various incarnations of the
method but didn't codify and version it until recently.
Another reason to contact me is that I no doubt have an updated version
that hasn't been uploaded yet if you do have any trouble with the one
currently on the site.
The fact that AppleScript does thumb its nose at you with the error:
"Can't make February into a string"
is actually a good sign, and suggests to me that you will find it
useful indeed.
<
http://homepage.mac.com/richard23/applescript01.html#CoerceToString>
R23