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



-- 
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

PLEASE always state which version of Microsoft Office you are using -
**2004**, X  or 2001. It's often impossible to answer your questions
otherwise.


> From: Bryan Harris <[EMAIL PROTECTED]>
> Reply-To: "Entourage:mac Talk" <[EMAIL PROTECTED]>
> Date: Sun, 24 Oct 2004 19:44:44 -0700
> To: "Entourage:mac Talk" <[EMAIL PROTECTED]>
> Subject: Script breaks in '04?
> 
> 
> 
> I have a script that inserts a date stamp into the current document that
> I've used since the OE days (I think...).  All of the sudden it inserts
> carriage returns between every element.  The result seems to be correct out
> of Script Editor, it just doesn't make it into Entourage correctly.  Anyone
> have any idea why it would start doing that?
> 
> e.g. Instead of "10/24/04", it does:  10
> /
> 24
> /
> 04
> 
> 
> See the script below.  TIA!
> 
> - Bryan
> 
> 
> 
> tell application "Microsoft Entourage"
>     
>     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
> 
> 
> --
> 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/>
> 
> 


--
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