0

I have tried using the script in Outlook 2011: Adding some messages to "Waiting for reply" folder. Basically, when I compose an Outlook message and hit Ctrl-Shift-W (as specified in the script name), it tries to send the message, find it in the sent folder and move it to a "waiting" folder. To make sure Outlook has a chance to send the message, it tries to delay before finding the message in the sent folder, repeatedly.

Unfortunately, the delay doesn't work (it doesn't delay), making it fail. Checking to do shell script "sleep 1s" means that Outlook is then stuck and doesn't send the message until the script fails.

I figured that outlook is waiting for the script to end before doing any background tasks. So the script needs to run in the background. Maybe launching an auxiliary script or something similar.

The problem is I don't know how to do this. Hence this question...

Community
  • 1
  • 1
IttayD
  • 28,271
  • 28
  • 124
  • 178

2 Answers2

0

While AppleScript does have its own sleep method (delay), what you are probably looking for is the idle handler. If you save your script as an application and check “Stay open after run handler”, Mac OS X will call your script’s idle handler immediately after your “run” handler finishes. Your idle handler then returns the number of seconds until the next time it should be called; this can happen indefinitely. In your case, it might look something like this:

global messageID

on run
    -- send message
    -- set messageID to whatever you are using as the just-sent message’s identifier
end run

on idle
    --check whether message exists in the sent folder
    --note that this is just pseudocode, you’ll need to change it for your purposes
    if exists messageID in sent folder then
        --do something with it
        quit
    else
        --wait another second
        return 1
    end if
end idle

This will repeat the idle every second until the criteria in the if is met at which point it will perform the task and quit the script.

Jerry Stratton
  • 3,287
  • 1
  • 22
  • 30
  • Sorry, but this doesn't work for me. it looks like the 'on idle' section never runs (i added a 'display notification' at the beginning). I saved as application and checked the 'Stay open...' and removed the previous script. Here's the app for reference: http://pastebin.com/t06shdBh – IttayD Nov 22 '14 at 02:11
  • My guess is that something in your tell Outlook block is causing the run handler to never end. I removed those two tell blocks (I don’t have Outlook), and saved the script as an application with Stay Open, and am now getting notifications every sixty seconds. You might try adding some notifications at the beginning and end of your run handler to verify this. – Jerry Stratton Nov 22 '14 at 02:49
  • well, it works if i run it directly, but not if i run it from outlook. so i guess there's something wrong with how outlook runs things – IttayD Nov 26 '14 at 01:01
0

You can try something like this:

ignoring application responses
    tell application "Microsoft Outlook"
        --send code goes here
        sync
    end tell
end ignoring

delay 5

tell application "Microsoft Outlook"
    -- Find code goes here...
end tell
adayzdone
  • 11,120
  • 2
  • 20
  • 37