Title: Re: Scripting the subject
On 5/21/04 7:55 AM, "Russell" <[EMAIL PROTECTED]> wrote:

> Ent 10.1,1 OS 10.3.3, 2000 Pismo
>
> I have the following script make the subject of my message the same as
> the attachment's name.
>
> However, if an attachment's name is file_for_meeting.pdf, I would like
> the subject to read:
>
> file for meeting
> (without the underscores or the .pdf)
>
> I think I know the syntax for replacing the underscore with spaces, and
> how to delete ".pdf", but I'm not sure where in the script they should
> go.

Do you? The script below gets the names of all attachments as a list, in one fell swoop. But you can't reset the names of all subjects in one fell swoop. (This is a restriction of AppleScript itself. Attempts to describe how such a thing might work usually run into roadblocks.) Anyway, you need to do the setting by a repeat loop, so it's best to get each name in the same repeat loop.

I'm going to assume that you run this script on a new message window after you drag attachments to it, yes?

And suppose the message has 10 attachments. Do you really want every single attachment's name in an immensely long subject? I'll do it that way for now, separated by commas.
>
> can I get a pointer?
>
> The script as it is now:
>
> tell application "Microsoft Entourage"
>     tell window 1
>         try
>             set theNames to name of every attachment
>         on error
>             return -99 -- silent exit
>         end try
>         try
>             set the subject to theNames
>         end try
>     end tell
> end tell


tell application "Microsoft Entourage"
    set theWindow to window 1
    if class of theWindow is not draft window then
       beep 2
        display dialog "You can only run this script on a new message window." buttons {"Cancel"} default button 1 with icon 0
        return
   end if
   
    set theNames to {}
    set theAttachments to every attachment of theWindow
   repeat with theAttachment in theAttachments
       set theName to name of theAttachment
       set AppleScript's text item delimiters to {"_"}
        set theBits to text items of theName
       set AppleScript's text item delimiters to {" "}
        set theName to theBits as Unicode text
       set AppleScript's text item delimiters to {"."}
        try
           set theName to text items 1 thru -2 of theName as Unicode text -- if there's an extension [or anything else after a period!]
       end try
       set AppleScript's text item delimiters to {""}
        set end of theNames to theName
   end repeat
   if theNames ≠ {} then -- i.e. there was at least one attachment
       set AppleScript's text item delimiters to {", "}
        set theSubject to theNames as Unicode text
       set AppleScript's text item delimiters to {""}
        set subject of theWindow to theSubject
   end if
end
tell

--
Paul Berkowitz

Reply via email to