month of current date

James Sentman james at sentman.com
Tue Jan 1 15:41:34 PST 2008


On Dec 31, 2007, at 8:26 PM, Michel-D wrote:

> Hi Guys,
> can you tell me why I obtain a "Bad".   My script is:
>
> set the_month to (text of xLabel "label1" in xView "XX") as string -- 
> the text in this label1 is January
>
> if month of (current date) = the_month and day of (current date) < 6  
> then
> write log "Cool"
> else
> write log "Bad"
> end if
>
>
> I tried as string, as text, as number. No result
> Please help me!!
> Michel
>

I think the problem is that months are a enumeration and not returned  
as text. So you could do something like:

if month of (current date) is January then

but putting it in quotes doesn't work like:

if month of (current date) is "January" then

so you just need to convert the month as coming from the date into a  
string:

set CurrentMonth to (month of (current date) as text)

And then you should be able to compare the 2. But if you're running  
under leopard then there is yet another layer of stupidness to have to  
deal with. All the strings in XTension are "UTF8" encoded, but all  
strings in AppleScript are now UTF16 encoded and so far even though  
XTension tells AppleScript what format it's strings are in AppleScript  
isn't smart enough to know that some strings are not UTF16 encoded  
when comparing them. So it my be necessary to do something really  
obscure like:

set CurrentMonth to ((month of (current date) as text) as «class utf8»)

no, you cannot just replace the as text with as «class utf8» it  
requires first a converstion to text and then the conversion to utf8.  
The other option is to convert the text that XTension is returning to  
utf16 before the conversion like:

set the_month to ((text of xLabel "label1" in xView "XX") as string)  
as unicode text)

I haven't yet figured out how I'm going to deal with this internally  
in XTension yet. I'm upset that changes in AppleScript have basically  
broken all strings returned by XTension (and many other apps) and made  
them useless for comparisons against constants in the scripts. But  
converting all the strings inside of XTension to utf16 just isn't a  
trivial task. I may be able to coerce ALL outgoing returns to  
applescript to UTF16, but some more experimentation is necessary.  
Short answer is that if you dont need to run Leopard yet, dont...


Thanks,
  James


James Sentman                       http://sentman.com		http://MacHomeAutomation.com





More information about the XTensionlist mailing list