Title: Script to open template text file [LONG]
--Insert Boilerplate -- For Outlook Express, by Allen Watson <[EMAIL PROTECTED]>
--April 11, 2000
--Adapted for Microsoft Enrourage, 10/30/2000 by Allen Watson

(*
When first run, prompts for a folder location that holds the text files of your boilerplate text. (The folder can also contain one level of subfolders.) The main location is remembered for later runs.

It presents you with a list of the files and folders in your boilerplate folder. Select one. If you choose a subfolder, you will be presented with a list of the files in the subfolder. When you have selected a text file (note that you MUST use files of type "TEXT" for boilerplate files), if you have an open new or outgoing message, the text from the file will be inserted at the cursor (insertion point); if text is selected it will be replaced by the boilerplate text.

If you do not have an open message in which to insert the text, a new draft message will be formed using the boilerplate text. The text will also be copied to the clipboard. You can paste it in wherever you like.
*)

property whichFolder : ""

on run
    try
        if (keys pressed) = {"Command"} then set whichFolder to "" -- Jon's Commands
    end try
    
    if whichFolder = "" then
        set whichFolder to (choose folder with prompt "Locate the folder holding your boilerplate text files.") as string
    end if
    --    tell application "Finder"
    set thePath to whichFolder
    set theNames to list folder thePath
    -- Limit list to TEXT files and folders
    set newNames to onlyText(theNames, thePath)
    set theNames to newNames
    set theChoice to choose from list theNames with prompt "Choose a file or folder" without multiple selections allowed and empty selection allowed
    if result is false then return
    set theChoice to item 1 of theChoice
    if theChoice ends with " �" then set theChoice to text 1 thru -3 of theChoice
    set isFolder to (folder of (info for (thePath & theChoice)))
    if isFolder then
        set thePath to thePath & theChoice & ":"
        set theNames to list folder thePath
        set theNames to my onlyText(theNames, thePath)
        set theChoice to choose from list theNames with prompt "Choose a file" without multiple selections allowed and empty selection allowed
        if result is false then
            set whichFolder to ""
            return
        end if
        set theChoice to item 1 of theChoice
        if theChoice ends with " �" then
            set theChoice to text 1 thru -3 of theChoice
            display dialog theChoice & " is a folder; can't go another level. Run again and select this level first."
            set whichFolder to ""
            return
        end if
    end if
    set theFile to alias (thePath & theChoice)
    set theText to read theFile
    --    end tell
    tell application "Microsoft Entourage"
        try
            set copied to true
            if (the class of the front window is draft window) or (the class of the displayed message of the front window is outgoing message) then
                copy theText to the selection of the front window
            else
                make new draft window with properties {content:theText, subject:theChoice}
            end if
        on error theErr
            set copied to false
            display dialog theErr
        end try
    end tell
    if not copied then
        try
            set the clipboard to theText -- Should work from Standard Additions
        on error -- But if it fails
            clip theText -- try the command from Akua Sweets
        end try
    end if
end run

on onlyText(theList, thePath)
    set newList to {}
    repeat with aName in theList
        --        display dialog aName
        set thetype to ""
        try
            set inf to info for (thePath & aName)
            set isFolder to (folder of inf)
            if (not isFolder) then
                set thetype to file type of inf
            else
                set thetype to "folder"
            end if
            if (thetype is "TEXT") or (thetype is "folder") then
                if thetype is "folder" then set aName to aName & " �"
                set newList to newList & aName
            end if
        on error theErr
            display dialog theErr
        end try
    end repeat
    return (newList)
end onlyText

--
Peace,
Allen Watson <[EMAIL PROTECTED]> XNS name: =Allen Watson
A Mac family since 1984
My web page: <http://home.earthlink.net/~allenwatson/>

Reply via email to