targendaz2 / Mac-Set-Default-Apps

A utility to change default applications in macOS
MIT License
85 stars 10 forks source link

Big Sur compatability? #2

Closed eduder closed 3 years ago

eduder commented 3 years ago

I am having trouble getting this to work on 11.2.3. I know the last release is from 2019 so I'm not sure if this is even supposed to work on Big Sur without modification.

Here is the output I get back: Setting Google Chrome as default browser. sudo: _mbsetupuser: command not found Traceback (most recent call last): File "/usr/local/bin/msda", line 474, in <module> subprocess.check_output(sudo_command.split() + kill_command.split()) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 223, in check_output raise CalledProcessError(retcode, cmd, output=output) subprocess.CalledProcessError: Command '['/usr/bin/sudo', '-u', 'sysadmin', '_mbsetupuser', '/usr/bin/killall', 'lsd']' returned non-zero exit status 1 Setting Adobe Acrobat as the default PDF reader. sudo: _mbsetupuser: command not found Traceback (most recent call last): File "/usr/local/bin/msda", line 474, in <module> subprocess.check_output(sudo_command.split() + kill_command.split()) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 223, in check_output raise CalledProcessError(retcode, cmd, output=output) subprocess.CalledProcessError: Command '['/usr/bin/sudo', '-u', 'sysadmin', '_mbsetupuser', '/usr/bin/killall', 'lsd']' returned non-zero exit status 1

targendaz2 commented 3 years ago

Hey, what command are you using to run MSDA? Also, how are you calling that command? (e.g. a Jamf policy, directly in Terminal, and Intune script, etc.)

While I haven't tested MSDA with Big Sur yet, I don't think this is a compatibility issue.

eduder commented 3 years ago

We use Mosyle MDM and I have been deploying it as a package install via "Custom Command"

I wasn't able to figure out how to deploy it as "script only" like in your JAMF documentation, as I don't see the same type of fields in Mosyle to add the extra variables to a custom command script.

I was also able to replicate by installing and running on a machine and manually running via terminal.

Here is the deploy script:

`#!/bin/bash

Set RMA Mac Defaults

msdapath="/usr/local/bin/msda" chromepath="/Applications/Google Chrome.app" acrobatpath="/Applications/Adobe Acrobat DC/Adobe Acrobat.app" msdapkg="https://INTERNAL-HOST-URL-HERE/pkg/msda/MacSetDefaultApps-v1.3.0.pkg"

Checks if MSDA is Installed

if [ -e "$msdapath" ]; then msdaInstalled=1 else msdaInstalled=0 fi

Checks if Google Chrome is Installed

if [ -d "$chromepath" ]; then GoogleChromeInstalled=1 else GoogleChromeInstalled=0 fi

Checks if Adobe Acrobat is Installed

if [ -d "$acrobatpath" ]; then AdobeAcrobatInstalled=1 else AdobeAcrobatInstalled=0 fi

Install MSDA if needed

if [ $msdaInstalled -eq 0 ]; then

Navigate to /private/tmp directory and download the MSDA Installer

cd /private/tmp curl -o msdaInstall.pkg "$msdapkg"

Change file permissions on installer

chmod a+x /private/tmp/msdaInstall.pkg

Execute the pkg installer

installer -allowUntrusted -pkg /private/tmp/msdaInstall.pkg -target /;

Clean Up

rm -rf /private/tmp/msdaInstall.pkg fi

Set Chrome as Default

if [ $GoogleChromeInstalled -eq 1 ]; then echo "Setting Google Chrome as default browser." $msdapath set com.google.chrome -p http -p https -p mailto -u public.url all -u public.html viewer -u public.xhtml all -fut -feu fi

Set Acrobat as Default

if [ $AdobeAcrobatInstalled -eq 1 ]; then echo "Setting Adobe Acrobat as the default PDF reader." $msdapath set com.adobe.acrobat.pro -u com.adobe.pdf all -fut -feu fi`

cornwella commented 3 years ago

This seems to be some oddity in Big Sur that tries to run the script as the initial deployment user (_mbsetupuser). We worked around this in Jamf by running the script on login, but excluding the "_mbsetupuser" from the policy. There may be a way to do the same thing in Mosyle, but I'm not familiar with it.

targendaz2 commented 3 years ago

I just released version 1.3.1. @eduder let me know whether this fixes this issue for you or not. @cornwella I imagine this will fix the issue you mentioned as well. See below if you want more info on what was happening.

It looks like the issue was that the logic to get the currently logged in user actually got every active user. Hence the following excerpts from the command output @eduder posted:

sudo: _mbsetupuser: command not found ['/usr/bin/sudo', '-u', 'sysadmin', '_mbsetupuser', '/usr/bin/killall', 'lsd']

Version 1.3.1 will only use the 1st active user MSDA finds. Additionally, if that user is _mbsetupuser, MSDA will now run its commands as root.

alexanderharm commented 3 years ago

I have exactly the same issue using Mosyle, although with a different approach.

/usr/local/bin/msda set org.libreoffice.script -feu -u org.openxmlformats.presentationml.presentation all

The results:

Traceback (most recent call last):
  File "/usr/local/bin/msda", line 475, in <module>
    exit_code = main(sys.argv[1:])
  File "/usr/local/bin/msda", line 461, in main
    return args.func(args)
  File "/usr/local/bin/msda", line 379, in set_command
    ls.write()
  File "/usr/local/bin/msda", line 289, in write
    create_plist_parents(plist)
  File "/usr/local/bin/msda", line 84, in create_plist_parents
    os.makedirs(parent_path)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/Users/container/Library/Preferences'
alexanderharm commented 3 years ago

Sorry, not sure what went wrong with my testing. The script works fine for me with Mosyle and BigSur run as root. The problem was that it is very very slow and the Mosyle interface seemingly timed out because I ran so many changes. All good for me.

eduder commented 3 years ago

@targendaz2 This does seem to be working now, thank you. Mosyle MDM has added a feature to have pre and post App Pkg install scripts, so what I've done was set up the msda pkg as a package to install on the Macs, and as part of the post-install script I have it run the command to set the defaults for Chrome.