0

I wan to change the content of the currently composed message and add the string *WF* at the end. Below is the script, I get an error Microsoft Outlook got an error: Can’t set content of draft window id 9490 to ...

on replace_chars(this_text, search_string, replacement_string)
    set AppleScript's text item delimiters to the search_string
    set the item_list to every text item of this_text
    set AppleScript's text item delimiters to the replacement_string
    set this_text to the item_list as string
    set AppleScript's text item delimiters to ""
    return this_text
end replace_chars

tell application "Microsoft Outlook"

    activate

    set theWindow to window 1

    -- check it's really draft
    if class of theWindow is not draft window then
        display dialog "Not a draft"
        return
    end if

    -- save the draft
    save theWindow

    --get the id of the object of the draft window
    set myObjectID to id of (object of theWindow)

    -- to make it secure
    set myContent to content of message id myObjectID

    --edit recipient
    -- set theBCC to bcc recipient of message id myObjectID
    -- set emailString to theBCC
    make new bcc recipient at message id myObjectID with properties {email address:{name:"Ittay Dror", address:"[email protected]"}}

    set myContent to my replace_chars(myContent, "</body>", "*WF*</body>")
    set the content of theWindow to myContent
end tell

1 Answer 1

0

you can't set the content of a window. Please set the content of the message:

set the content of message id myObjectID to myContent

Cheers, Michael / Hamburg

2
  • But then the contents of the window stay the same. is there a way to read from the message?
    – IttayD
    Sep 30, 2014 at 9:46
  • close theWindow before the last end tell saves the content. I didn't find any other way... If you want to do something else with the message, you can open it again with open message id myObjectID
    – ShooTerKo
    Sep 30, 2014 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.