Title: Re: AppleScripting outgoing messages
On 7/1/02 4:38 AM, "Rick Johnson" <[EMAIL PROTECTED]> wrote:

> Thanks, Paul,
>
> For getting me on the right track. I got the script working (except for the
> cursor location), thanks to your advice, and used it for this message! All
> it really does is insert a couple of blank lines and a simple signature
> above the quoted text. I may go back and update it to work on saved drafts,
> but since this is the first step I do in any reply, it's unlikely I'd ever
> need that. Here's the script:

A few corrections below
>
> ---
>
> tell application "Microsoft Entourage"
>   set w to window 1
>   
>  (* if w is {} then
>       return
>   end if *)

w will never , ever be {}. If no window at all exists, line 1 will error and you'll never get to line 2. Close all the windows, run your script, and you'll see. The script will break with an error: "Microsoft Entourage: Can't get window 1." I can't imagine there never being a window 1, but if you want to protect against it, do this:

    try
        set w to window 1
    on error
        beep 2
        display dialog "There are no windows open." buttons {"OK"} default button 1 with icon 0
        return
    end try
    
>   
>   if class of w � draft window then
>       return
>   end if
>   
Again, it's probably a good idea to insert and explanation:

         if class of w � draft window then
            beep
            display dialog "The script only works with a new message window open in the front."  buttons {"OK"} default button 1 with icon 0
            return
        end try

>   set signature type of w to none
>   
>   set s to content of w
>   
>   set intro to (ASCII character 13) & (ASCII character 13) & ¬
>       "Rick" & (ASCII character 13) & "=====" & (ASCII character 13) & ¬
>       (ASCII character 13)

No. A horribly inefficient way to do this. (ASCII character x) is  call to a scripting addition, so there's a separate overhead each time. For any other ASCII character, I'd suggest setting a variable to it, then using the variable 5 times  much better. But in the case of ASCII character 13, there already IS an AppleScript constant for CR : 'return'. Yes, I know it's the same _English word_ as the 'return' that ends a script or handler, but AppleScript understands the context and will compile it as the correct constant. (If you have different AppleScript formatting for 'keywords' , i.e. events and classes, vs. 'AppleScript language', you'll see it compile differently.) In fact, even as you've typed it, the compiler will actually compile it like this when you press the Check Syntax button:

      set intro to return & return  & ¬
      "Rick" & return  & "=====" & return  & ¬
      return

So cut out the line continuations too:

     set intro to (return & return  & "Rick" & return  & "=====" & return  &  return)


Just let it wrap if it needs to.

>   
>   set s to intro & s
>   
>   set content of w to s
>   
> end tell
>
> ---

The rest of it is good.
>
> I added "\cI" to the file name so I just begin each reply with Ctl-I and
> Cmd-Home and start typing. Again, thanks for the advice!

Ctl-I seems to be an existing built-in shortcut that selects the first character of the NEXT blank line or containing only a "reply" > symbol (is this some hackie I have, or Entourage?) , so I suggest another one, such as ctl-O or ctl-U. OMM, Cmd-Home brings the window to the top, but does NOT insert the cursor, whereas cmd-up arrow , which I recommended last time, DOES insert the cursor. Perhaps some of these things are because I do not "use Microsoft Office shortcuts for editing text" in general preferences and perhaps you do? That might account for it.

You're doing pretty well. There's always lots to learn. AppleScript is moderately forgiving: there are usually many ways to do the same thing, and it's good to learn optimized techniques, especially for syntax, that will pay off when you're doing more complex script and repeat loops that repeat the same process many times later on.
>

PB

>
> On 6/30/02 6:25 PM, "Paul Berkowitz" <[EMAIL PROTECTED]> wrote:
>
>> On 6/30/02 4:03 PM, "Rick Johnson" <[EMAIL PROTECTED]> wrote:
>>
>>> I'd like to try my first Entourage X AppleScript, but I'm not sure if what I
>>> want to do is practical, or even possible.
>>>
>>> If the current window is an outgoing message, I'd like to do two things:
>>
>> Windows aren't messages. They ay be displaying messages and/or they may be
>> 'draft windows': unsaved new message windows..
>>>
>>> 1) Insert predefined text at the cursor location and move the cursor to the
>>> beginning of the inserted text. "source of message" seems it should return
>>> the text of the message, but is there a way to get or set the cursor
>>> location?
>>
>> 'source' is not what you want here. You can insert text at the cursor
>> location in a draft window (previously saved draft messages can be re-opened
>> as draft windows too):
>>
>>   if class of window 1 is draft window then
>>   
>>       set selection to "Some new text here. "
>>
>>   end if
>>
>> But no, there is mo way at all to reset the cursor location. you could do I
>> in Entourage 2001 with the use of suitable scripting additions (Sigma's
>> Additions, for example) but these don't exist or work in OS X. Yes, perhaps
>> with QuicKeys you could record yourself typing command-up arrow, which will
>> do it (and which you could emulate with Sigma's, Sandi's or Akua).
>>>
>>> 2) Change the signature to "None."
>>
>>   That's easy enough:
>>
>>   set signature type of window 1 to none
>>
>> Only works for draft windows, so include it in the 'if' clause. (If you ever
>> send news messages, then that first line should be instead:
>>
>>   if {class of window 1} is in {draft window, draft news window} then
>>   
>>       set selection to "Some new text here. "
>>       set signature type of window 1 to none
>>
>>   end if
>>
>>
>> If you save window 1, it becomes an outgoing message, and you can access
>> various message properties this way:
>>
>>   save window 1 -- saves in drafts folder
>>   set theMsg to displayed message of window 1
>>   -- close window 1 saving yes  -- alternate possibility
>>
>> or you may not need to do that all. Just
>>
>>   send window 1
>>
>>>
>>> I've written a few scripts for the Finder and Adobe Illustrator, but I seem
>>> to be at a loss with this one. I'd appreciate any suggestions, even if it's
>>> just to buy QuicKeys.
>>>
>>
>>
>
>
>
> --
> 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/>
>


--
Paul Berkowitz

Reply via email to