Paul, thanks for a script that I didn't think I needed until you made it.
It's awesome!

//k


On 10/25/04 12:01 PM, "Bryan Harris" <[EMAIL PROTECTED]> wrote:

> 
> 
> Thanks, Paul -- for the lesson and for the fix!
> 
> Chastisement taken, too.  I guess I should quell your fears at least a
> little -- this particular script was heavily borrowed from elsewhere, I just
> tweaked the output.  I do know about ATIDS, I was just unaware that they
> only stick while the application that ran them is still running.  And I
> didn't know the part about the concatenation to lists vs. strings part.  I
> had no idea on that one, thanks.
> 
> I must admit that I've become much more fond of perl in the last couple
> years and grown more annoyed with AS, for this very reason!  I did try to
> build this script, but I couldn't get what I wanted from it in a reasonable
> amount of time.  Why is "&" able to return lists *and* strings?  Where is it
> documented that you can request the month of a date as an integer?  The
> month of the current date is "October", how does AS coerce that into an
> integer?  More generally, unreliable globals, properties that don't always
> stick, and English-like syntax that usually isn't, make AS pretty difficult
> when perl is available.  Of course none of this is your fault -- just a
> source of frustration for me.
> 
> Thanks again.
> 
> - Bryan
> 
> 
> 
>> You've recently run a script that set AppleScript text item delimiters to
>> {return}, and your own script does not set them to {""} before coercing a
>> list to text ('as string'). That is a VERY big no-no. Never omit that.
>> 
>> This script is simply full of careless things that show a lack of
>> understanding of AppleScript. I'm afraid.
>> 
>> This actually proves the point that you can never trust others to reset
>> delimiters so you should always, always set them to what you want before
>> coercing a list to string or Unicode text.
>> 
>> AppleScript's text item delimiters are global across the application running
>> the script(s), until you quit and relaunch it. In the case of scripts run
>> from the Entourage script menu, that means Entourage itself. So running a
>> script form the Script menu which sets tids to {return} will leave them that
>> way for all other scripts run from the menu until you quit and relaunch.
>> Therefore it's polite to always reset them to {""} - or to what they were.
>> And it's essential to set your own before coercing lists to strings.
>> 
>> Now you may think you're not using a list anywhere. But you are.
>> 
>> You have the line:
>> 
>>     if mo < 10 then copy "0" & mo as string to mo
>> 
>> OK, what happens when mo � 10? Nothing - it remains an integer - you have
>> not coerced it to string. Then later, when you have:
>> 
>> 
>>         copy (mo & "/" & da & "/" & yr as text) to theTxt
>> 
>> 
>> The first element (mo) is integer and the rest of the items, beginning with
>> "/", are strings. You can always begin a concatenation expression with a
>> string followed by an integer, e.g.
>> 
>>     "/" & 10
>>     --> "/10"
>> 
>> 
>> since the integer will get coerced implicitly to the class on the left
>> (string) , since it _can_ be. But when you write
>> 
>>     10 & "/"
>>     --> {10, "/"}
>> 
>> you get a list, since the item on the right cannot be implicitly coerced to
>> an integer. All this is in the AppleScript Language Guide. Thus, on today's
>> date
>> 
>>     (mo & "/" & da & "/" & yr )
>>     --> {10, "/", 24, "/", "04"}
>> 
>> There's your list. Since you have tids set to {return} when you then coerce
>> this list - at last - to text, you get:
>> 
>>         copy (mo & "/" & da & "/" & yr as text) to theTxt
>> -->"10
>> /
>> 24
>> /
>> 04"
>> 
>> 
>> 
>> tell application "Microsoft Entourage"
>>   
>>     set AppleScript's text item delimiters to {""}
>>     copy ((offset of (the month of (current date)) in �
>>         "jan feb mar apr may jun jul aug sep oct nov dec ") + 3) / 4 �
>>         as integer to mo
>>     if mo < 10 then copy "0" & mo as string to mo
>>     copy day of (current date) to da
>>     copy text 3 thru 4 of (get year of (current date) as text) to yr
>>     if (day of (current date) < 10) then copy "0" & da as string to da
>>     
>>     copy (mo & "/" & da & "/" & yr as text) to theTxt
>>     
>>     try
>>         set selection to theTxt
>>     on error
>>     display dialog "This script can only insert into the body of a message"�
>>     buttons {"OK"} default button 1 with icon stop
>>     end try
>>     
>> end tell
>> 
>> 
>> 
>> 
>> ( By the way, all this 'copy' stuff is bad practice too. It doesn't matter
>> in this script, but when repeated many times will make your scripts slower
>> and eat up memory. 'copy' makes a new copy every time. Expect in the cases
>> of lists, records and dates where you do not want to share data (they're
>> mutable), always use 'set' instead of copy. 'copy day of current date to da'
>> is the only line that needs 'copy'. And why is any of this - aside from 'set
>> selection to theTxt' - in an Entourage tell block anyway?
>> )
>> 
>> On top of all this, in Panther you don't need any of that guff since you can
>> just get the month 'as integer' without offsets. You also keep calling
>> 'currnet date' osax over and over again instaed of setting avariable to it
>> just once. I'd do the script like this:
>> 
>> 
>>     set currDate to (current date)
>>     set mo to (month of currDate) as integer
>>     set mo to text -2 thru -1 of ("0" & mo) -- string
>>     set da to text -2 thru -1 of ("0" & (day of currDate))
>>     set yr to (year of currDate as string)
>>     set theTxt to (mo & "/" & da & "/" & text 3 thru 4 of yr) --not list
>>     tell application "Microsoft Entourage" to set selection to theTxt
>> 
>> 
> 
> 
> --
> To unsubscribe:
> <mailto:[EMAIL PROTECTED]>
> archives:
> <http://www.mail-archive.com/entourage-talk%40lists.letterrip.com/>
> old-archive:
> <http://www.mail-archive.com/entourage-talk%40lists.boingo.com/>
> 



Kyle DeMilo
__________________________
demilokyle AT sbcglobal DOT net

http://macfixer.blogspot.com

Get Firefox: Take back the web
http://www.mozilla.org/


--
To unsubscribe:
<mailto:[EMAIL PROTECTED]>
archives:
<http://www.mail-archive.com/entourage-talk%40lists.letterrip.com/>
old-archive:
<http://www.mail-archive.com/entourage-talk%40lists.boingo.com/>

Reply via email to