Skip to main content
Question

Script to open an outlook compose window


Forum|alt.badge.img+3

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

mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • April 7, 2017

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.


Forum|alt.badge.img+3
  • Author
  • New Contributor
  • 5 replies
  • April 7, 2017

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.


mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • April 7, 2017

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

Forum|alt.badge.img+3
  • Author
  • New Contributor
  • 5 replies
  • April 7, 2017

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
Forum|alt.badge.img+36
  • Community Manager
  • 1900 replies
  • April 8, 2017

@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.


Forum|alt.badge.img+11
  • Contributor
  • 13 replies
  • August 23, 2019

@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


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings