Advertisement
rtfmoz

Instructions

Jan 15th, 2021
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. What does this do?
  2.  
  3. When you connect or disconnect from any network, it checks for the proxy and adjusts the macOS network location profile accordingly. Because its a shell script a whole host of conditions can be setup to suit any user environment and potentially multiple customers - hey @todd.
  4.  
  5. Min Requirements
  6. macOS Catalina.
  7.  
  8. Installation (does not require root)
  9. - Create new location profile in networking called On-Net.
  10. - Switch to it and update its proxy settings to point to what you prefer.
  11. - Switch back to your default profile called Automatic.
  12. - Copy the networkchange.sh shell script to /usr/local/bin
  13. - Load the plist file with launchctl load networkchange.plist
  14. - Test it works as you expect and adjust to suit.
  15. - Make it permanent by moving the plist file into ~/Library/LaunchAgents/
  16.  
  17. How does it work?
  18. Launchd watches the resolv.conf file for any changes and if they occur it runs the script. Any network change updates resolv.conf which launchd sees and then runs the shell script. The script then does a simple network connection check to the proxy. If it succeeds it changes the location to On-Net. If not it changes the location to Automatic.
  19.  
  20. Notes
  21. The location profile names can easily be changed in the networkchange.sh script to whatever you use now.
  22. This solution uses built in capabilities of macOS. No external utilities are required.
  23.  
  24. Future tasks
  25. Update the users shell script to add/remove proxy environment variables.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement