Script to open an outlook compose window

edelcastillo
New Contributor II

Hello,

I am trying to find for a script where it would open a new email window on 2016 MS outlook with a pre filled "TO:" field and everything else is blank. I tried different scripts i found online but non of them worked.

thanks

6 REPLIES 6

mm2270
Legendary Contributor III

The following Applescript does the trick.

tell application "Microsoft Outlook"
    activate
    set sendToAddress to "someone@company.com"
    set theMessage to make new outgoing message with properties {subject:""}
    make new recipient at theMessage with properties {email address:{name:"FirstName LastName", address:sendToAddress}}
    open theMessage
end tell

You would need to replace the someone@company.com with a real email address, and also the "FirstName LastName" with their name or just use the same string as the email address.

By the way, it can only be done with Applescript. Outlook and other MS apps don't work with things like shell scripts.

edelcastillo
New Contributor II

Thanks for your help! it works on applescript editor i just changed tell application "Microsoft Outlook" to tell application "/Applications/Microsoft Outlook.app" However, when I applied it on self service and ran the command, it asked me to download command line developer tools otherwise it will not complete the command.

3e8c231ecde448e7ab721a75377452a7

mm2270
Legendary Contributor III

You don't need to provide a full path to an application in Applescript to get the script to address an application. A simple tell application "Microsoft Office" is enough to get the app to open. Were you seeing something different when you ran it? Applescript won't understand something like tell application "/Applications/Microsoft Outlook.app" because that's a POSIX path that hasn't been specified as such in the script, so it won't really know what to do with that.

As for the Xcode dialog prompt, I'm guessing what you'd need to do is wrap this AS into a bash script and execute it that way from a Casper/Self Service policy. It's possible the way it was created in the JSS it's not seeing it as an Applescript or something.

Try doing this

#!/bin/sh

/usr/bin/osascript <<EOF
tell application "Microsoft Outlook"
    activate
    set sendToAddress to "someone@company.com"
    set theMessage to make new outgoing message with properties {subject:""}
    make new recipient at theMessage with properties {email address:{name:"FirstName LastName", address:sendToAddress}}
    open theMessage
end tell
EOF

edelcastillo
New Contributor II

Thanks! the only reason why i provided the full path is because every time i run it, it opens my MS office on parallels. I tried doing your script but for some reason it still won't run but this time xcode isn't showing up anymore. I'm almost there. i just need to do a little more research. Thank you!

talkingmoose
Moderator
Moderator

@edelcastillo, Parallels does have a setting to disable shared applications in your VM's configuration settings. This would avoid having to enter the path in your script. It's all or nothing, though, so if you like some of your files to just open in the Windows apps, this won't be your solution.

Naren
New Contributor III

@mm2270 Thank you for sharing this short script to compose mail., I am finding difficult in attaching zip file.

I am extracting logs to user Desktop with .Zip file

zip "${logdir}.zip"

/usr/bin/osascript <<EOF
tell application "Microsoft Outlook" activate set sendToAddress to "support.mac@xyz.com" set theMessage to make new outgoing message with properties {subject:"Self Service: $HostName Logs for Analysis"} make new recipient at theMessage with properties {email address:{name:"MAC Support, xyz company support.mac@xyz.com", address:sendToAddress}} open theMessage
end tell
EOF