2

I have a local mail rule I'd like to apply on a schedule. To apply all rules manually, I can click the Message menu -> Rules -> Apply -> Apply All.

Is there a way to automate this action with Applescript? I looked through the dictionary for Outlook and didn't find any actions relating to rules.

Alternately, is there a way to do this with Automator?

craig65535
  • 3,439
  • 1
  • 23
  • 49

2 Answers2

5

Can be solved with GUI scripting to faux click the menu item, using the System Events app.

You end up with quite long menu references, but it works.

Edit: I have added how to make sure the inbox is selected first.

tell application "Microsoft Outlook"
    activate
    if main windows is {} then -- no windows open
        make new main window
    end if

    tell main window 1 to set view to mail view -- ensure its viewing mail

    set the selected folder to inbox    
end tell

tell application "System Events"
    tell process "Microsoft Outlook"
        click menu item "Apply All" of menu 1 of menu item "Apply" of menu 1 of menu item "Rules" of menu 1 of menu bar item "Message" of menu bar 1            
    end tell
end tell
adamh
  • 3,222
  • 1
  • 20
  • 16
  • Unfortunately, a part of the folder tree (for example, the Inbox) needs to be selected for this to work. – craig65535 Mar 03 '14 at 20:00
  • @craig65535 You could select it with gui scripting or Outlook as well possibly? – adamh Mar 03 '14 at 21:42
  • additionally it makes sense that something needs to be selected to be operated on. – adamh Mar 03 '14 at 21:55
  • This seems great, but in practice it switches focus every time it runs, and still, for me, throws this error if the Outlook main window is open but not in focus: http://i.imgur.com/5L70NYU.png – Ky - Jan 28 '15 at 15:43
1

Problem

You'd like a way to apply a mail rule via applescript on a schedule.

Solution

You can use GUI scripting to accomplish this goal. To capture the appropriate GUI script you should look into the trial version of UI Browser (good for 30 days). This software will allow you to capture the applescript needed to execute the specific rules on your system.

Once you have the script complete you can save the script as an application using the AppleScript Editor. Then you can create a calendar event in your MacOSX calendar. Schedule the event for whenever you need the script to run. Then in the alert box select a custom alert and choose to open a file (point this to your saved script application):

adding a script app to calendar

Tommie C.
  • 12,895
  • 5
  • 82
  • 100