Set Outlook and Excel as Default Apps

ntavassoli
New Contributor II

I'm trying to follow the documentation for deploying SwiftDefaultApps in order to make Outlook the Default Mail Reader and Excel the default app for CSV files for our production fleet of over 300 MacBook Air M1's.

I'm using GitHub - Lord-Kamina/SwiftDefaultApps: Replacement for RCDefaultApps, written in Swift. for material.  I am also referencing this article for deploying a script via policy Configuring a Mac’s Default Apps for Different File Types | apizz (wordpress.com).

 

Here's my dumbed down verison of the script from wordpress:

#!/bin/bash
# Set default apps for users
SWDA="/usr/local/bin/swda"
MAIL="/Applications/Microsoft Outlook.app"
SHEET="/Applications/Microsoft Excel.app"
### MAIL ###
# Default mail client
$SWDA setHandler --app "$MAIL" --mail
# mailto: links
$SWDA setHandler --app "$MAIL" --URL mailto
# message
$SWDA setHandler --app "$MAIL" --URL message
# email
$SWDA setHandler --app "$MAIL" --UTI com.apple.mail.email
### FILE TYPES ###
# .csv
$SWDA setHandler --app "$SHEET" --UTI public.comma-separated-values-text

 

The error I get after running is this below:

ntavassoli_1-1690896795918.png

 

Im a novice in scripting so not sure if I need to make the "usr/local/bin/swda"?  If I make that directory then I would get an error saying that "/usr/local/bin/swda: is a directory".

 

Any help here is appreciated.

 

1 ACCEPTED SOLUTION

ntavassoli
New Contributor II

Ended up using MailToOutlook for Outlook and ran a script on each device to remove Numbers from it - this defaults all CSV files to Excel since there is no other app on the machine.  An easy workaround as of right now.

View solution in original post

10 REPLIES 10

sdagley
Esteemed Contributor II

@ntavassoli You have to copy the swda executable to the Mac you want to run it on. To do that you'd:

  1. Download https://github.com/Lord-Kamina/SwiftDefaultApps/releases/download/v2.0.1/SwiftDefaultApps-v2.0.1.zip
  2. Copy the swda binary to /usr/local/bin
  3. Use Composer to create a .pkg installer for the swda binary in that location
  4. Upload the .pkg you created to your JSS
  5. Add that .pkg to your Policy that's running the script to set the default apps (make sure the script is set to run After)

ntavassoli
New Contributor II

Sweet!  Im on the right track I believe but when the policy runs it shows this error now:

ntavassoli_0-1690900360056.png

Is there a way to trust this binary via Jamf so I dont run into this issue via deployment?

sdagley
Esteemed Contributor II

@ntavassoli You need to clear the quarantine flag on the swda binary:

sudo xattr -d com.apple.quarantine /Path/to/swda

ntavassoli
New Contributor II

So it runs successfully but no change is made on either of my test devices.  The script shows this output:

 

Executing Policy Excel and Outlook set as Default

Downloading swda.pkg...

Downloading https://use1-jcds.services.jamfcloud.com//download/2e13a3a0b5bb4bd2b692b75c6965ff80/swda.pkg...

Verifying package integrity...

Installing swda.pkg...

Successfully installed swda.pkg.

Running script Set Excel and Outlook to default apps...

Script exit code: 0

Script result: SwiftDefaultApps SUCCESS: Default handler has succesfully changed to com.microsoft.Outlook

SwiftDefaultApps SUCCESS: Default handler has succesfully changed to com.microsoft.Outlook

SwiftDefaultApps SUCCESS: Default handler has succesfully changed to com.microsoft.Outlook

SwiftDefaultApps SUCCESS: Default handler has succesfully changed to com.microsoft.Outlook

SwiftDefaultApps SUCCESS: Default handler has succesfully changed to com.microsoft.Excel

mm2270
Legendary Contributor III

FWIW, I use the "MailToOutlook_2.0.pkg" hosted on https://macadmins.software/tools/, which was built by Paul Bowden from the Microsoft Mac team. It works like a charm to set Outlook to the default email client. I don't think there's one for Excel, but, I've never had to set Excel to the default in my experience. I guess if Apple Numbers is also installed on the Mac that could end up taking precedence for spreadsheet files.

ryan_ball
Valued Contributor

This is a per-user setting. You have to run each swda command as the logged in user. See the below example.

#!/bin/bash

loggedInUser=$( echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ && ! /loginwindow/ { print $3 }' )
loggedInUID=$(/usr/bin/id -u "$loggedInUser" 2>/dev/null)

/bin/launchctl asuser "$loggedInUID" /usr/local/bin/swda setHandler --browser --app "/Applications/Google Chrome.app"

exit 0

 

Still not working for Excel. Do I have this setup correctly?

#!/bin/bash

loggedInUser=$( echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ && ! /loginwindow/ { print $3 }' )
loggedInUID=$(/usr/bin/id -u "$loggedInUser" 2>/dev/null)

/bin/launchctl asuser "$loggedInUID" /usr/local/bin/swda setHandler --app '/Applications/Microsoft Excel.app' --UTI 'public.comma-separated-values-text'

exit 0

 

Script is deployed through a Policy that is assigned Once per user per computer.  The policy contains the SWDA binary as a package as well.

ryan_ball
Valued Contributor

What you have looks correct. I've tested it on my Mac, and it does not work in that case for Excel/CSV. Unless a logout is required which I'm not doing now. 😁

Have you tested the other commands? What version of macOS are you running? Perhaps swda might have stopped functioning.

But my goodness, trying to insert code in Jamf Nation posts in block or inline is just atrocious now.

ryan_ball
Valued Contributor

And no I'm not a robot, what in the world! 😐

ntavassoli
New Contributor II

Ended up using MailToOutlook for Outlook and ran a script on each device to remove Numbers from it - this defaults all CSV files to Excel since there is no other app on the machine.  An easy workaround as of right now.