Title: Re: Update for Log Attachments Scripts?
On or near 1/29/02 9:14 PM, MGSeeley at [EMAIL PROTECTED] observed:

> I had been successfully using the Log Attachments scripts (particularly Save
> and Remove with Log) from Philip Kearney in Ent 2001 but it causes Ent X to
> crash.
>
> I checked the web site Philip has listed within the scipt description
> <http://www.avernus.com/~phil/OEStuff.html> but he does not appear to have
> updated any of his scripts for OS X. I also sent him an email and am
> awaiting a reply.
>
> Has anyone gotten these scripts to work, or know why they won't? Are then
> any other scripts out there that are similar?

I use the following script, named for its emulation of Claris Emailer behavior. It saves the attachment and logs in the message the path to where the file was saved. It handles multiple attachments. I've modified the script for my own use, adding a property at the top with multiple folder paths to my favorite folders for saving files.

For instance, I get a weekly database update from my home office, so that goes to my "Office Database" folder; I work with a writer named Robert who sends me files from time to time, which I save in "Robert's Writing". I've replaced my actual folder paths with dummy ones; you will need to insert your own. Having just a single path is fine, if you wish; I found having a short list of favorites extremely useful.

I'll post this to AppleScript Central "real soon." Oh! I didn't write the original script.

!Claris It! -- A script for Microsoft Entourage to save attached files to disk, logging the location in the original message.
Named for its similarity to a feature of the classic Claris Emailer application.

Original author: Robert Buckley. The original README file is appended below. Adapted by Allen Watson for Entourage 2001 and Entourage v. X. Several changes from the original edition have been made:

1. folderList property: Instead of prompting just once for a folder when you first use the script, this version requires you to
edit the script to define the property "folderList" (near the top of the script). You can have as many entries in this list as you like, except that the final entry must be "Other". When you run the script it will display the list of folders to let you double-click the one in which to store the file(s). The first time you run the script, it will prompt you to add your folders, delete any folders already in the list, or modify them. If you ever wish to further modify the list, you can simply open the script, type a space at the end of any line to "modify" the script, and save it. The next run will seem to be the "first" run, and the code to modify the list will run.

2. This version does not insert clickable URLs for the file. I will provide, soon, a companion script that will open the filespec when you select the spec and run the script.


Claris It!

Claris It! imitates Claris Emailer's enclosure behaviour by saving all attachments in a folder of the user's choice and removing them from the original message, making a note of the details at the start of the message.It also adds a clickable URL that links to the attachment.

How to Work It
Define an incoming mail rule in OE to run the script when a message has attachments. You should make it the last rule in the list because you won't be able to execute any further rules afterwards. You can put the script anywhere you like. Which messages you apply the rule to is up to you but "Messages with attachments" runs quicker than "all messages". The first time you use the script (or if you get rid of the folder), it will prompt you to choose a location to store your attachments in)

Notes
After the attachments have been removed, OE still reports the message's original size. This is true even if you compress the database by holding down the option key at start-up.

Requirements
OE 5.0.

--Robert Buckley
   [EMAIL PROTECTED]

property theFolder : ""
(* Edit the following list of favorite folders to contain your own folders.
   Do not eliminate 'Other' at the end, however; it must come last. *)
property folderList : {"BigDisk:Downloads:", "BigDisk:Databases:", "BigDisk:Documents:Business:Robert's Writings:", ¬
    "BigDisk:Documents:Text Commentaries:", "Other"}
property firstrun : true

on checktheFolder(theAlias)
    if theAlias is not "" then
        try
            theAlias as alias
        on error
            return false -- alias does not check out
        end try
    else
        return false -- the alias is blank
    end if
    return true
end checktheFolder

on PromptFolderAlias()
    set theAlias to choose from list folderList with prompt ¬
        "Pick a folder to save in, or Other to choose another" default items {""} with empty selection allowed
    if theAlias is "Other" or theAlias is {"Other"} then
        try
            set theAlias to (choose folder with prompt "Choose a folder to save attachments in") as text
        on error
            display dialog "OK, I'll ask again next time." buttons {"Quit"} default button 1
            set theAlias to ""
        end try
    end if
    return theAlias
end PromptFolderAlias

on run
    if firstrun then
        display dialog "You can edit the property \"folderList\" to contain your favorite target folders." & return & "You cannot delete 'Other' at end of list." buttons {"Continue"}
        display dialog "To add a new folder, click Add; to Change or delete existing folders, click Modify." buttons {"Add", "Modify"} default button "Add"
        set b to button returned of result
        if b is "Modify" then
            repeat with i from 1 to ((count folderList) - 1)
                display dialog "Click Retain to retain item, Delete to delete, or edit and click Change." buttons {"Retain", "Delete", "Change"} ¬
                    default answer (get item i of folderList) default button 1
                set {b, t} to {button returned, text returned} of result
                if b is "Delete" then set item i of folderList to "removed"
                if b is "Change" then set item i of folderList to t
            end repeat
            set temp to {}
            repeat with i from 1 to (count folderList)
                if item i of folderList is not "removed" then
                    set temp to temp & item i of folderList
                end if
            end repeat
            set folderList to temp
        else -- Add a new entry to the list
            set newf to choose folder "Select new favorite folder to add to list."
            set t to newf as text
            set item -1 of folderList to t
            set folderList to folderList & "Other"
        end if
        display dialog "Do you want to make more changes?" buttons {"Yes", "No"} default button "No"
        if button returned of result is "No" then
            set firstrun to false
        else
            display dialog "Please rerun the script to make another change."
            return
        end if
    end if
    tell application "Microsoft Entourage"
        --        if my checktheFolder(theFolder) is false then
        set theFolder to my PromptFolderAlias() as text
        --        end if
        --        display dialog theFolder
        if theFolder is "" then
            display dialog "No folder chosen; exiting."
            return
        end if
        activate
        set theMsgs to current messages
        --        display dialog "" & (count theMsgs) & " messages"
        repeat with theMsg in theMsgs
            beep (count theMsgs)
            try
                tell theMsg
                    set newContent to ("Attachments saved to disk:" & return)
                    set theDetails to ""
                    if encoding of attachment 1 is in {binhex, AppleDouble} then -- avoid crash from null data handler returned for file type of non-Mac files
                        try
                            set theTypes to file type of attachments
                            set theCreators to file creator of attachments
                            set theAttachmentCount to the number of attachments of theMsg
                            repeat with m from 1 to theAttachmentCount
                                set theDetails to theDetails & (name of attachment m) & " (" & text 8 thru 11 of ((item m of theCreators) as text) & "/" & text 8 thru 11 of ((item m of theTypes) as text) & ")" & return & my makeURL(my stripper(attachment m)) & return
                            end repeat
                        on error
                            say "Error path"
                            set theDetails to theDetails & my makeTheDetails(attachments)
                        end try
                    else
                        --                        say "Not binhex"
                        set theDetails to theDetails & my makeTheDetails(attachments)
                    end if
                    set content to newContent & theDetails & "--------" & return & return & content
                    delete attachments
                end tell
            on error theErr
                display dialog theErr
            end try
        end repeat
    end tell
end run

on stripper(vcffile)
    tell application "Microsoft Entourage"
        set vcffilename to name of vcffile
        if vcffilename contains ":" then
            set fileName to my stripColons(vcffilename)
        else
            set fileName to vcffilename
        end if
        if (count of characters of fileName) > 28 then
            set fileName to (text from character 1 to character 27 of fileName & "…")
        end if
        set newPath to (theFolder & fileName)
        set tryPath to newPath
        repeat with j from 1 to 100
            if j = 100 then
                beep 2
                set color to {62001, 0, 1}
                with timeout of 10000 seconds
                    display dialog "Process stopped — unable to save file “" & vcffilename & "”. Possibly a name conflict. Check the red message." buttons "OK" default button 1
                end timeout
                error number -128
            end if
            try
                alias tryPath
            on error
                exit repeat
            end try
            set tryPath to newPath & " " & (j as text)
        end repeat
        save vcffile in tryPath
        return tryPath
    end tell
end stripper

on makeURL(theText)
    set theCount to the count of characters in theText
    set i to 2
    repeat until i > theCount
        try
            if character i of theText is " " then
                set theText to (text from character 1 to character (i - 1) of theText) & "%20" & (text from character (i + 1) to character theCount of theText)
                set theCount to theCount + 2
            end if
            if character i of theText is ":" then
                set theText to (text from character 1 to character (i - 1) of theText) & "/" & (text from character (i + 1) to character theCount of theText)
            end if
            set i to i + 1
        end try
    end repeat
    set MacSpec to myReplace("%20", " ", theText)
    set MacSpec to myReplace("/", ":", MacSpec)
    return MacSpec & return
    --    return "file:///" & theText & return -- Original code
end makeURL


on makeTheDetails(namelist)
    tell application "Microsoft Entourage"
        set theExtras to ""
        repeat with theAttachment in namelist
            set theExtras to theExtras & my makeURL(my stripper(theAttachment)) & return
        end repeat
        return theExtras
    end tell
end makeTheDetails

on stripColons(aString)
    set oldDelims to AppleScript's text item delimiters
    set AppleScript's text item delimiters to ":"
    set theString to text items of aString
    set AppleScript's text item delimiters to "."
    set theString to theString as text
    set AppleScript's text item delimiters to oldDelims
    return theString
end stripColons

on myReplace(fstr, wstr, instr)
    set sd to AppleScript's text item delimiters
    set AppleScript's text item delimiters to fstr
    set temp to text items of instr
    set AppleScript's text item delimiters to wstr
    set temp to temp as text
    set AppleScript's text item delimiters to sd
    return temp
end myReplace
--
Microsoft MVP for Entourage/OE/Word
Allen Watson <[EMAIL PROTECTED]> XNS name: =Allen Watson
Applescripts for Outlook Express and Entourage: <http://homepage.mac.com/allenwatson/>

Reply via email to