Title: Re: sort text script
On or near 11/3/2000 3:42 PM, Bryan Harris at [EMAIL PROTECTED] observed:

Hey, Bryan!

Not sure exactly how I helped with this. Useful addition. I already had a sort text script in OE, but I converted your script for Entourage. Works fine just with a change of program name.

On the inability to undo: I added some code to your script, using some commands from Akua Sweets since that is already required for the script, so that a use can select the same (sorted) text and hold down Control to undo the sort. Like Cmd-Z, you have to do this immediately, or it won't work right. What I do is to store the unsorted text in a property variable in the script, so it is remembered. When you re-execute the script, holding down Control just makes the script replace whatever is currently selected with the original text. Not perfect, but better than nothing. I've replaced your version of the script below with my revised version. It has "Microsoft Entourage" in the "tell" statements. OE users need to edit and change that to "Outlook Express".

> A while back with Paul's help I wrote a sort-text script and submitted it to
> the list.  Thanks to some help from Paul and Allen (though he doesn't know
> it yet), I've updated it to work in almost every situation.  (It's a
> derivative from the ROT13 script.)  It'll sort the selected text in a
> message, or whole message if none is selected, whether it be an outgoing or
> incoming message, open window or not.
>
> Requires Akua Sweets, available from versiontracker or osaxen.
>
> It works fine, but use at your own risk.  Generally speaking there's no
> undo, so sorting a message from an employee will make it a little tougher to
> read.  (Unless he's a lawyer, of course...)
>
> - B
>
>
> ****************************************************************************
> Copy the following text, then paste it into a Script Editor window.  Save it
> as a compiled script, and drop that script into the Script Menu Items folder
> (i.e., in Documents:Microsoft User Data:<your identity>:Script Menu Items).
> ****************************************************************************
>
-- Sort Text 1.2
-- Modified by Allen Watson, 6 November 2000, added "undo" ability.
-- Sort Text 1.1
-- adapted by Bryan Harris, 3 November 2000

-- Adapted from ROT13 Encode-Decode 2 by Bryan Harris
-- which includes portions of ROT13 Encode-Decode by Allen Watson, 10/25/2000

-- requires Akua Sweets OSAX, available from http://www.versiontracker.com/ or http://www.osaxen.com/
property originalText : ""

tell application "Microsoft Entourage"
    
    if button returned of (display dialog "To undo a previous sort operation, select the same text and hold the Control Key down." with icon caution) is "Cancel" then return
    
    if class of front window is draft window then save the front window
    
    set theMsgs to current messages
    
    if (count of theMsgs) is 0 then
        display dialog "Cannot find any text to sort.  Select the message you wish to" & ¬
            "sort, or some text within an editable message." buttons {"Ok"} default button 1 with icon stop
        return
    end if
    
    set theMsg to item 1 of theMsgs
    
    set wholeMsg to false
    
    set thesel to selection
    
    if thesel is "" or (class of thesel � string) then
        set thesel to content of theMsg as string
        set wholeMsg to true
    end if
    
    set keyState to the input state -- Also uses Akua Sweets
    if control key bit of keyState is true then -- Undo the prior sort
        set newSel to originalText
        set originalText to thesel
    else
        -- perform operation on text here
        
        set prevDelims to AppleScript's text item delimiters
        set AppleScript's text item delimiters to {return}
        
        set theEnd to ""
        set originalText to thesel -- Save for a possible Undo.
        
        set theList to every text item of thesel
        if (the last item of theList) is "" then
            set theList to items 1 through ((count of theList) - 1) of theList
            set theEnd to return
        end if
        set sortedList to order list theList
        set newSel to (sortedList as text) & theEnd
        
        set AppleScript's text item delimiters to prevDelims
    end if
    -- /perform operation on text here
    
    if wholeMsg then
        set content of theMsg to newSel
        if class of front window is draft window then -- draft windows don't update properly without closing and reopening
            set theBounds to bounds of front window
            close front window without saving
            open theMsg
            set bounds of front window to theBounds
        end if
    else
        try
            set selection to newSel
        on error
            if button returned of (display dialog "This is uneditable text.  You can try selecting \"Edit Message\" from " & ¬
                "the Message menu, then running the script again, or simply click \"Place in new window\" to put the sorted " & ¬
                "text into a new draft window." buttons {"Place in new window", "Ok"} default button 2 with icon stop) ¬
                is "Place in new window" then
                make new draft window with properties {content:newSel}
            end if
            return
        end try
    end if
    
end tell

--
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