targendaz2 / Mac-Set-Default-Apps

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

Permission Denied for Standard User Account #1

Closed jadomski closed 4 years ago

jadomski commented 4 years ago

This version 1.0 package is not working for a standard local user account. I'm seeing the below responses from terminal when debugging.

In the first attempt I tried to only make the change for the current user and not all users. For the second attempt I tried to make the change for all users. Same result for both.

username@hostname ~ % msda set com.google.chrome -p http -p https -u public.url all -u public.html viewer -u public.xhtml all       
Traceback (most recent call last):
  File "/usr/local/bin/msda", line 403, in <module>
    exit_code = main(sys.argv[1:])
  File "/usr/local/bin/msda", line 399, in main
    return args.func(args)
  File "/usr/local/bin/msda", line 329, in set_command
    ls.write()
  File "/usr/local/bin/msda", line 251, in write
    create_plist_parents(plist)
  File "/usr/local/bin/msda", line 83, 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 150, in makedirs
    makedirs(head, mode)
  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/username\n'
username@hostname ~ % msda set com.microsoft.outlook -p mailto -fut
Traceback (most recent call last):
  File "/usr/local/bin/msda", line 403, in <module>
    exit_code = main(sys.argv[1:])
  File "/usr/local/bin/msda", line 399, in main
    return args.func(args)
  File "/usr/local/bin/msda", line 329, in set_command
    ls.write()
  File "/usr/local/bin/msda", line 251, in write
    create_plist_parents(plist)
  File "/usr/local/bin/msda", line 83, 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 150, in makedirs
    makedirs(head, mode)
  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/username\n'
jadomski commented 4 years ago

Yes, sudo works, however not in the standard user. By default, macOS does not allow a standard user to run a sudo command, and this is one of the requirements in many corporate deployments.

When I run the command with sudo as an administrator user, it does not change the defaults of the standard user account on the machine.

targendaz2 commented 4 years ago

Hi there!

My mistake, I completely blanked out on how sudo works for a second. You'll need to run the script as a user with administrative privileges. I'll update the read me to make this clear.

I'll also implement a feature to target another user using the command.

jadomski commented 4 years ago

Is it possible to implement a feature to target all users using the command? I'm looking to deploy this into a situation where the username of the standard user will not be consistent as those details are coming from an upstream directory server during device enrolment.

Thanks for the great work so far by the way. You are the real MVP!

targendaz2 commented 4 years ago

Thank you very much!

That's actually the feature I'm working on implementing next. I'll update this issue once it's implemented.

targendaz2 commented 4 years ago

I just published a new release of the app. You can target all existing users via the -feu switch. Let me know how it goes!

jadomski commented 4 years ago

Unfortunately, it's still not working.

After installing v1.2.0 I tried the following commands:

sudo msda set com.google.chrome -p http -p https -u public.url all -u public.html viewer -u public.xhtml all -feu
sudo msda set com.microsoft.outlook -p mailto -feu -fut

There are no longer any errors displayed, but none of the users on the system are updated. to use Chrome or Outlook.

I am running Catalina if that makes any difference.

targendaz2 commented 4 years ago

Strange. I ran the commands you specified on a clean Catalina system running MSDA 1.2.0 and the latest versions of Google Chrome, Outlook 2019, and Catalina. Both the default browser and default mail client were updated after a system restart.

Just to confirm, did you restart the computer in question after running the MSDA commands? If so, if I sent you a script that would gather the files that MSDA modifies into a zip archive, would you be comfortable sending me that archive?

jadomski commented 4 years ago

The restart did the trick!

I'm not certain how majority of users will be deploying this tool, so unsure whether it would be better to add the restart as a step in the documentation or simply let the users know that a restart will be required when the command has finished running.

targendaz2 commented 4 years ago

Glad to hear it!

I actually just released a version (v1.3.0) that removes the need to restart and applies the changes immediately.

jadomski commented 4 years ago

That's fantastic! This tool is an absolute godsend. Thanks again for the work you're doing!

targendaz2 commented 4 years ago

No problem! I'm glad you find it useful and really appreciate the feedback!