@talkingmoose This is a great script! thank you for creating it. I am having trouble using it in my environment as the DOMAINusername method does not work even when done manually. It accepts username@domain (which differs from the email domain). Any suggestions?
other than that, the script works very well.
@wmateo, you're more than likely looking for User Principal Name (UPN). Assuming you're connecting to Active Directory, you can read this from the directory and use it directly. Do this:
- Look for this section under "Begin collecting user information":
set userFirstName to ""
set userLastName to ""
set userDepartment to ""
set userOffice to ""
set userCompany to ""
set userWorkPhone to ""
set userMobile to ""
set userFax to ""
set userTitle to ""
set userStreet to ""
set userCity to ""
set userState to ""
set userPostalCode to ""
set userCountry to ""
set userWebPage to ""
set userPrincipalName to "" < -- Add this line
- Look for this section too. Add "userPrinicpalName" to the end.
set userInformation to do shell script "/usr/bin/dscl "/Active Directory/" & netbiosDomain & "/All Domains/" -read /Users/$USER AuthenticationAuthority City co company department physicalDeliveryOfficeName sAMAccountName wWWHomePage EMailAddress FAXNumber FirstName JobTitle LastName MobileNumber PhoneNumber PostalCode RealName State Street userPrincipalName"
- Lower in the same section, find one of the several script blocks that looks like the following, duplicate it and modify it for userPrincipalName:
set AppleScript's text item delimiters to {": "}
if paragraph i of userInformation begins with "dsAttrTypeNative:userPrincipalName:" then
try
set userUPN to text item 2 of paragraph i of userInformation
on error
set AppleScript's text item delimiters to {""}
set userUPN to characters 2 through end of paragraph (i + 1) of userInformation as string
end try
end if
- Look for the "Begin logging user information" section and modify it:
writeLog("User information...")
writeLog("First Name: " & userFirstName)
writeLog("Last Name: " & userLastName)
writeLog("User Principal Name: " & userUPN) < -- Add this line
writeLog("Email Address: " & emailAddress)
writeLog("Department: " & userDepartment)
writeLog("Office: " & userOffice)
writeLog("Company: " & userCompany)
writeLog("Work Phone: " & userWorkPhone)
writeLog("Mobile Phone: " & userMobile)
writeLog("FAX: " & userFax)
writeLog("Title: " & userTitle)
writeLog("Street: " & userStreet)
writeLog("City: " & userCity)
writeLog("State: " & userState)
writeLog("Postal Code: " & userPostalCode)
writeLog("Country: " & userCountry)
writeLog("Web Page: " & userWebPage)
writeLog(return)
- Finally look for this section under "Begin account setup" and modify "user name" to use userUPN:
try
set newExchangeAccount to make new exchange account with properties ¬
{name:"Mailbox - " & userFullName, user name:userUPN, full name:userFullName, email address:emailAddress, server:ExchangeServer, use ssl:ExchangeServerRequiresSSL, port:ExchangeServerSSLPort, ldap server:DirectoryServer, ldap needs authentication:DirectoryServerRequiresAuthentication, ldap use ssl:DirectoryServerRequiresSSL, ldap max entries:DirectoryServerMaximumResults, ldap search base:DirectoryServerSearchBase, receive partial messages:downloadHeadersOnly, background autodiscover:disableAutodiscover}
my writeLog("Create Exchange account: Successful.")
on error
I haven't tested these changes myself, but I think these should be all you need to do.
You are the man!! Thank You!! worked like a charm. @talkingmoose
On the OutlookExchangeSetupLaunchAgent.plist do I have to edit anything in there in order for the scripts to work. When I launch Outlook 2016 the scripts are not kicking in unless I run the Apple Script manually.
@Jaxson75, you'll find a log in the user's ~/Library/Logs folder. What does it say?
Thank you @talkingmoose this is awesome.
I just have one question, we are also deploying office templates and because of this the /Users/$USER/Library/Group Containers/UBF8T346G9.Office folder already exists. I tried to change some parts in your OutlookExchangeSetupLaunchAgent.sh to check the /Users/$USER/Library/Group Containers/UBF8T346G9.Office/Outlook folder but it didn't work.
Honestly I'm no programer i just tried ;)
Hope you or anyone else has a hint for me.
Thank you
BR
Daniel
@dpratl, thanks for the kudos!
First, no need to deploy templates to each user's home folder. You can place them in /Library/Application Support/Microsoft/
for all users. See this document: http://macadmins.software/docs/UserContentIn2016.pdf.
The OutlookExchangeSetupLaunchAgent.sh script is looking for the existence of this folder in the current user's home folder: "$HOME/Library/Group Containers/UBF8T346G9.Office"
You've identified that part perfectly. If it's already there then the script assumes the user already has Office preferences and setup doesn't happen.
You can correct this one of two ways:
- You can move your template files to the
/Library/Application Support/Microsoft
folder that I mentioned above and then remove the "$HOME/Library/Group Containers/UBF8T346G9.Office"
from each user folder.
You can try modifying this part of the script and see if that works.
Change:
if [[ -f "$HOME/Library/Group Containers/UBF8T346G9.Office/OutlookProfile.plist" ]] ; then
logresult "$HOME/Library/Group Containers/UBF8T346G9.Office/OutlookProfile.plist already exists. Doing nothing." "$HOME/Library/Group Containers/UBF8T346G9.Office/OutlookProfile.plist does not exist but it should exist already. Something may be wrong."
fi
to:
if [[ -f "$HOME/Library/Group Containers/UBF8T346G9.Office/OutlookProfile.plist" ]] ; then
logresult "$HOME/Library/Group Containers/UBF8T346G9.Office/OutlookProfile.plist already exists. Doing nothing."
else
/usr/bin/touch "$HOME/Library/Group Containers/UBF8T346G9.Office/OutlookProfile.plist"
logresult "$HOME/Library/Group Containers/UBF8T346G9.Office/OutlookProfile.plist does not exist but it should exist already. Creating the file."
fi
Thank you @talkingmoose - awesome scripts and super fast response time :D
I have to put the templates into that folder because if i don't Word and Outlook doesn't use them as default template. (Excel and PowerPoint are not working till now but at least Outlook and Word ;)
I did the changes you suggest but it looks like the script is not starting at all (also no entry into your log file)
If i run it per hand it is writing that it creates the plist file and launch agent.
I'm sorry to bother you because of my damn templates.
@dpratl, be sure to test this setup for a user under a different OS X user account.
If your user logs in, the launch agent in /Library/LaunchAgents should trigger the shell script. Even if Outlook is already configured, that shell script should say something in the log. Having an empty log tells me the launch agent isn't running at login.
Launch agents require very specific ownership and permissions, which the installer should set. If you view these settings in Terminal, you should see something like:
ls -l /Library/LaunchAgents/
total 40
-rw-r--r-- 1 root wheel 595 Jul 26 07:58 net.talkingmoose.OutlookExchangeSetupLaunchAgent.plist
Hi @talkingmoose Do you have any insight as to whether there is a way to suppress the following autodiscover prompt? There is apparently a reg key hack for Windows, but I have not seen anything for macOS at this point.

@ocla&&09, that's a user setting and I'm pretty sure it's stored in Outlook's SQLite database within its identity. I wouldn't attempt modifying the database or you may cause Outlook to rebuild it.
Other than the user clicking the Allow button and enabling the option to always use that response, you can run an AppleScript command. However, it requires Outlook be running under the user's account. The command is:
tell application "Microsoft Outlook" to set background autodiscover of exchange account 1 to false
You can replace the 1
with the actual name of the account if you have more than one.
Careful with doing this, though. If the user travels, you could disable Outlook from connecting when it attempts to connect from external networks.
I completely get this feature is confusing to users and suggest you voice your concern to Microsoft here: https://outlook.uservoice.com/forums/293343-outlook-for-mac/suggestions/12255774-autodiscover
Thank You @talkingmoose, does this also disable autodiscover from the perspective of setting up a new account on a machine in the account prefs window (ie all or nothing), or is this just the background checks after the fact that the command verbage implies?
@ocla&&09, you won't be able to disable Autodiscover until you have an Exchange account created. To work around that, you can use AppleScript to set Outlook to work offline, create the account, disable Autodiscover and then set Outlook to work online again.
tell application "Microsoft Outlook"
set working offline to true
set background autodiscover of exchange account 1 to false
set working offline to false
end tell
Haven't tested this, but I think it's the right syntax.
First off... I love my Talking Moose script....
I love it even more because its called Talking Moose.... I remember that app.....
But apparently we are doing a slow phased migration to Office 365. So Hard-coding the exchange server in the script doesn't work for everyone and I have no way of discerning who has been migrated already. AutoDiscovery should work but that doesn't seem to be an option in the current script. Is there a way to use auto-configure with this script- or is that a whole new project?
@AdamH, I love hearing someone remembers the app! It was the first computer program that showed me computers could be fun.
I wrote the script for environments where Autodiscover wasn't available. At the time I was using it, I was educating my Exchange folks about Autodiscover, but they were pretty slow to enable it.
Outlook's AppleScript dictionary does support calling Autodiscover:
tell application "Microsoft Outlook"
autodiscover email address "bill@talkingmoose.net" user name "bill@talkingmoose.net"
end tell
It returns something like:
{use ssl:true, server:"https://outlook.office365.com/EWS/Exchange.asmx",
primary smtp address:"bill@talkingmoose.net",
oab manifest url:"https://outlook.office365.com/OAB/2d1f6b5f-c74d-0000-b7f4-fbbda4ee8c30/",
port:443, full name:"William M. Smith", ldap server:""}
I've just never considered modifying the script to support Autodiscover if it already works. It would take a bit of work to redo the script to support Autodiscover (maybe version 6.0?), but if you're familiar with how to take the output above and slip it into the properties at the top of the script, then that should be all you need.
Completely understand. If it were up to me, I'd have people just input their name and email and be done with it. But the script has spoiled the user base so much now that the expectation is that they will only need to input a password to start using Outlook.
I'm not a great scripture, but I do ok modifying other people's scripts, so the pointers you gave here should give me a good start. Thanks a bunch!

OK, this is going to be trickier than I thought.
Without dealing with variables, I thought it may look something like:
tell application "Microsoft Outlook"
try
set exchnageInfo to autodiscover email address "mac.user@domain.com" user name "macuser1"
set newExchangeAccount to make new exchange account with properties {exchangeInfo}
end try
end tell
It calls up the right information and prompts for credentials like it may be expected to, but it doesn't actually create the account with that info.
@talkingmoose this is awesome! I only have one issue. When I configure using this script, I can't seem to show shared calendars when I choose Open Shared Calendar. However, if I were to remove the account, and add it manually, I can Open Shared Calendars just fine. Is this happening to anyone else?
Thanks for the kudos, @rickwhois!
No idea why configuring using a script vs. manual would affect opening shared calendars. Are you sure you're using the exact same settings?
Also, have you disabled Autodiscover in the script? That might cause this behavior, but I haven't tested.
@talkingmoose how do you handle signatures? we want our users to have and image, and text similar how Windows handles. Signature templates
@wmateo Not sure how others have doen this...
We did it by having an HTML template signature and associated images with unique tags that we replaced with data pulled from AD (name, email, phone number, title, etc..), we then used an Applescript call to Outlook to create a new signature using this template.
Unfortunately I am now off work until after the new year so can't easily check the scripting for you.
@Look Since our AD enviroment is not really cleaned up yet. I was looking for a way to "prefill" the Signature area with a few default images, and dummy fields so user can enter name themselves.
Well you can definately make an Applescript call to Outlook 2016 and tell it to create a new signature using an HTML file as the source, if you have any linked image files in the same directory and in the right format (png I think is what I used) then it will embed these in the signature as wel, this is new behaviour as of a fairly recent version upgrade, previously it just linked images, which sucked.
Not quite sure how the best way to go about creating the HTML signature, ours was originally supplied to me by branding, it was massively over complicated so I pulled it apart and rebuilt it with half the code, but it did mean it had all the correct stuff specified at the top, maybe you can export it in HTML from Windows or something, not sure.
@talkingmoose Thoughts on updating an existing Outlook 2016 account with a new directory service server name? Something like this?
tell application "Microsoft Outlook"
try
set ldap server:xxxxxxxxxxx
end try
end tell
@kbach, the syntax is close. You also need to specify the account. You may also want to set the other properties of the LDAP server (just to be thorough). I think the "try" statement is a good idea. Give this a shot:
tell application "Microsoft Outlook"
try
set ldap server of exchange account 1 to "ldap.company.com"
set ldap needs authentication of exchange account 1 to true
set ldap use ssl of exchange account 1 to true
set ldap port of exchange account 1 to 3269
set ldap max entries of exchange account 1 to 1000
-- rarely need to set this, but would be something like "CN=Users,DC=talkingmoose,DC=net"
set ldap search base of exchange account 1 to ""
end try
end tell
Optionally, you can replace the "1" in exchange account 1
with the Account Description if you want to call it by name:
set ldap server of exchange account "My Exchange Account" to "ldap.company.com"
AppleScript is pretty much the only way to set these attributes. It will require Outlook be running or it will launch Outlook automatically if it's not running. This probably isn't something you want to just spring on your users.