0

My use case is that I want to track for responses on some messages I write. My methodology now is to wait for the message to be sent the move it from the sent folder to the "Waiting for reply" folder which I go over periodically.

I'm looking for a way to automate this. Best would be if I press a key which makes Outlook both send the message and put it in the Waiting folder. E.g., by using an applescript.

Alternatively, I thought that pressing a key will add me as BCC, and also add a "WF" string at the bottom of the message. Again, with applescript. Then when I send the message it will also arrive at my Inbox where I'll have a rule to move messages to "Waiting" if they contain "WF"

IttayD
  • 28,271
  • 28
  • 124
  • 178

1 Answers1

1

I expanded the script from your other thread to this here:

tell application "Microsoft Outlook"
    -- Simple definition of target mail folder
    -- Works fine this way if only one folder with this name is available
    set waitingForReplyFolder to folder "Waiting for reply"

    -- bring Outlook to front
    activate

    -- remember the front window
    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)

    -- close the message window
    close theWindow

    -- checking the message' subject
    set theSubject to subject of message id myObjectID

    -- send the message
    send message id myObjectID

    -- check and wait until Outlook has moved the mail to the sent folder
    -- move it to target folder after we have found it
    set mailFoundAndMoved to false
    repeat 20 times
        -- check the next 20 message ids
        repeat with idCounter from 1 to 20
            try
                set freshSentMail to outgoing message id (myObjectID + idCounter)
                -- check if the subject is the same (just to be safe)
                if subject of freshSentMail is equal to theSubject then
                    -- move the sent mail to the "waiting for reply" folder
                    move freshSentMail to waitingForReplyFolder
                    set mailFoundAndMoved to true
                    exit repeat
                end if
            on error errstr
            end try
        end repeat
        if mailFoundAndMoved then exit repeat
        delay 0.5
    end repeat

end tell

Now you must just see how to trigger this. Open a new message, write the content etc. and run this script. It will send the mail and move it to your target folder, just after it appeared inside the sent folder.

Cheers, Michael / Hamburg

Community
  • 1
  • 1
ShooTerKo
  • 2,242
  • 1
  • 13
  • 18
  • Super! Thanks for putting in the effort. – IttayD Oct 01 '14 at 11:49
  • There is a bug somewhere which I can't figure out. Basically I think that the delay doesn't work sometimes which ends up with the script not waiting enough for the message to appear in Sent. I've increased the delay to 1 and put log statements logging the current timestamp before each delay (using `(time of (current date))`). What I see in the log is that many messages contain the same timestamp (just now I see 10 with 38311 and 10 with 38312, meaning the script finished the loop within 2 seconds). Since the log is just before the delay statement, I still expect the delay to happen. – IttayD Nov 06 '14 at 08:43
  • It turns out this doesn't work. Outlook doesn't do anything while the script is running, so not sending/syncing. Maybe this is related to the issues with the delay command I wrote in the previous comment. I solved that one by using `do shell script "sleep 1s"`, but then outlook is stuck for the total sum of delays and the script fails. – IttayD Nov 16 '14 at 14:39
  • According to http://lists.apple.com/archives/applescript-users/2014/Nov/msg00092.html the `delay` seems to be broken in Applescript applets! Do you get any error or just a timeout? – ShooTerKo Nov 16 '14 at 15:52