Title: Re: scripting an "attach"
On or near 2/2/2001 11:49 AM, Bryan Harris at [EMAIL PROTECTED] observed:

>
>
> (I would ask this to Paul directly, but I thought others might be interested
> as well..)
>
>
> Is there a way to script the attaching of a certain file to a message?
>
> i.e. Given an open draft window, run the script and have it attach a pre-set
> file to the message.
>
I have the following script that in essence attaches a file to a draft message. It prompts with a list of scripts from the ESMI folder, lets you select one, and then attaches that. You could easily cut out the whole selection part and just hard-code the file you want to attach.

tell application "Microsoft Entourage"
    activate
    set c to current messages
    if c is not {} then
        set aMsg to item 1 of c
        if class of aMsg is outgoing message then
            set MyDisk to (path to startup disk) as string
            set x to info for (MyDisk & "Documents:")
            if alias of x is true then
                tell application "Finder" to set oi to original item of alias file (MyDisk & "Documents:")
                set MUD to ((oi as string) & "Microsoft User Data:")
            else
                set MUD to (MyDisk & "Documents:Microsoft User Data:")
            end if
            set scrptFldr to MUD & "Entourage Script Menu Items:"
            repeat
                set curList to the entries in scrptFldr whose kinds are a file
                set fldrs to the entries in scrptFldr whose kinds are a folder
                set curList to curList & {"**Folders**"} & fldrs
                --                set curList to list folder scrptFldr
                set theChoice to choose from list curList with prompt ¬
                    "Pick a script or subfolder." without multiple selections allowed
                set thisItem to scrptFldr & theChoice
                try
                    tell application "Finder" to set thisItem to alias thisItem
                on error
                    return
                end try
                set thisItem to thisItem as string
                if last character of thisItem is not ":" then exit repeat
                set scrptFldr to thisItem
            end repeat
            
            -- If backslash appears in file name, duplicate because it is applescript's escape character
            set thisItem to my SearchReplace(thisItem, "\\", "\\\\")
            try
                make new attachment at aMsg with properties {file:thisItem}
            on error theErr
                display dialog theErr
                return
            end try
        else
            beep
            display dialog "You can attach only to an outgoing message." with icon 0
        end if
    else
        display dialog "Please select a message and try again."
        return
    end if
end tell
-- routine to do a search and replace on text
on SearchReplace(mainString, searchString, replaceString) -- Parameters: search, replace, the String
    set olddelis to AppleScript's text item delimiters
    
    set AppleScript's text item delimiters to (searchString)
    set theList to (every text item of mainString)
    
    set AppleScript's text item delimiters to (replaceString)
    set theString to theList as string
    
    set AppleScript's text item delimiters to olddelis
    return theString
end SearchReplace

--
Peace,
Allen Watson <[EMAIL PROTECTED]> XNS name: =Allen Watson
A Mac family since 1984 <http://home.earthlink.net/~allenwatson/>
Applescripts for Outlook Express and Entourage: <http://homepage.mac.com/allenwatson/>

Reply via email to