Title: Re: New Note from Selected Text (trying to write)
On 2/4/01 12:17 PM, I wrote:

          And what would I need to change to make this create an Event rather than a note?
          
          
          -- Script from a message sent by Paul Berkowitz
          -- on Thursday, October 12, 2000 8:42:53 PM
          (* Modified ever so slightly by Jim Baskins on October 18, 2000 from Paul's Make Event
          Selected Text Script. *)
          
          But it looks as if i never posted it anywhere but here. I'll repair that. it would have
          been something like this:
          

On getting ready to post this script to AS central, I realized a couple of things about it: it would be a bad idea to make multiple events (so far without dates) and not open them, as they could never be found. So if you want to select a slew of messages in the message pane and make multiple events, they will all open. Also a number of error traps needed to be put in, in case there are no messages selected, or a message is open in its own window but some part of the header is "selected" or the cursor is up in in the headers (AppleScript says "can't get selection" and would have failed, but this new version will use the message content anyway). In the process I discovered an extremely weird AppleScript anomaly (I don't think it has anything to do with Entourage.)

------------------MAKE EVENT SELECTED TEXT--------------------



tell application "Microsoft Entourage"
    
    try
        set theMessage to displayed message of window 1
    on error -- not a message window or preview pane
        try
            set theMessages to current messages
            set selectedText to ""
            repeat with i from 1 to (count theMessages)
                set theMessage to item i of theMessages
                my MakeEvent(theMessage, selectedText)
            end repeat
            return
        on error
            beep
            display dialog "You must have a message open in the main window's preview pane or in its own window, or at least one message selected in the message pane, for this script to work." buttons {"OK"} default button "OK" with icon 0
            return
        end try
    end try
    try
        set theSelection to the selection
        if class of theSelection = string then
            set selectedText to theSelection -- could be "" if focus is in message text
        else
            set selectedText to ""
        end if
    on error -- may be nothing selected in front, or induced errors above        
        set selectedText to ""
    end try
    
    my MakeEvent(theMessage, selectedText)
end tell


to MakeEvent(theMessage, selectedText)
    
    tell application "Microsoft Entourage"
        
        set theName to text returned of (display dialog "Enter a Name for this Event" default answer "Type New Event Name Here")
        if theName = "" or theName = "Type New Event Name Here" then
            set theName to subject of theMessage
        end if
        set theCategory to category of theMessage
        
        if selectedText = "" then set selectedText to content of theMessage
        -- create a new event with the information from the message
        set newEvent to make new event with properties {subject:theName, category:theCategory, content:selectedText}
        
        -- create a link between the message and the new note
        link theMessage to newEvent
        
        open newEvent
        
    end tell
    
end MakeEvent


---------------END SCRIPT-----------------------------------

--
Paul Berkowitz

Reply via email to