Run a script on Outlook 2016 startup

automatorms office

I'd like to run a script on startup of Outlook 2016, so it runs as one of the first actions once Outlook is open.

One example of this would be to automatically switch to a certain view on every start, something that isn't possible using Outlook's preferences.

I don't see an "app startup" trigger in Automator, but maybe I've missed something. Is there a way to do this generally?

Best Answer

One approach would be to write an applescript to load Outlook and then execute the script.

Copy the following to a new script using Script Editor in Applications/Utilities

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

on run
    tell application "Microsoft Outlook"
        activate

        -- now tell Outlook to do other stuff
    end tell

    -- if you have another script already written that you want to run, then
    set theScript to ("path:to:script.scpt") as alias
    run script theScript

    -- or if your script takes arguments like the this:
    --on MsgBox(Msg)
    --  display dialog Msg
    --end
    set theScript to load script file ("path:to:script.scpt")
    tell theScript
        MsgBox("Hello World!")
    end tell
end run

You can save the applescript as a applet (Save As -> select "Application" for type), rename it to Outlook 2016 and change its icon to match the Outlook 2016 icon and leave it on your dock in place of Outlook itself. The downside is that, when Outlook is running, you'll have both the Outlook dock item and the applet on your dock, but that's a small price to pay.

Another approach is to make a silent program that checks to see if Outlook is running or not.

When the running status of Outlook changes from false to true, it will run a script. This involves making an applescript applet that will run at startup, stay open all the time, and be hidden from the dock. It will consume very little resources, but it's still a price to have it running all the time.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
--  Need to save with "Stay Open" option

property CheckTimeSeconds : 60 --   controls the number of seconds between each check to see fi Outlook is running

property WasRunning
property IsRunning

on run
    set WasRunning to false
    set IsRunning to false
    return
end run

on idle
    set IsRunning to appisrunning("Microsoft Outlook")

    if IsRunning and not WasRunning then -- Outlook has been opened in the last CheckTimeSeconds seconds.
        --run script here
    end if

    set WasRunning to IsRunning

    return CheckTimeSeconds
end idle

on appisrunning(appName)
    tell application "System Events" to (name of processes) contains appName
end appisrunning
  1. Save as an application with the "Stay open after run handler" option selected
  2. Set the program to have no dock icon
  3. Load the program at login for your user (drag your application into the list at System Preferences -> Users & Groups -> Login Items)

If you want to close this program, you'll have to do so manually from Activity Monitor.