Skip to content

Conversation

@ccarstens
Copy link
Contributor

What does this PR do?

Adds retry of the networksetup commands when macOS requires an admin password for system wide changes.

How did you verify your code works?

I activated System Settings -> Privacy & Security -> Advanced -> Require...

What are the relevant issues?

Closes #311

Comment on lines +81 to +84
cmd = elevate.WithPrompt("System changes required to activate proxy").Command("sh", "-c", strings.Join(retryCommands, " "))
if out, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("network setup with root privileges: %w (%q)", err, out)
}
Copy link
Member

@anfragment anfragment Jun 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like unfortunately elevate doesn't allow executing networksetup commands when "Require an administrator password to access system-wide settings" is on. Instead of setting uid to 0 like sudo does, elevate only sets euid to 0, which is apparently not enough for networksetup.

Here are two ideas on how to move forward:

  1. Run the commands via AppleScript with osascript -e "do shell script "<;-separated commands>" with administrator privileges with prompt "Authorize Zen to modify system proxy settings". This works, however the displayed prompt shows osascript in the title, which might confuse some users:
image
  1. Another solution that may work is to just call networksetup -setautoproxyurl without the other two commands. I'm struggling to find any official documentation on this, but local testing suggests that "automatic proxy configuration" (PAC) takes precedence over "web proxy" and "secure web proxy", which probably makes setting their state to "off" redundant.

@ccarstens @AitakattaSora thoughts on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Retry networksetup commands with elevate if they fail with Command requires admin privileges

2 participants