Search code examples
bashmacosmacos-sierracharles-proxy

Charles App - command line to toggle macOS proxy


I am having issues with Charles App with browser-sync. The only way I can get browser-sync to work is to toggle charles off reload a page and turn it back on to carry on working.

Charles has command line options. Does anyone know the command to toggle the macOS proxy on and off? I want to able to automate this sort of thing

Thanks


Solution

  • When you enable or disable the macOS proxy in the Charles application, the application modifies the HTTP and HTTPS proxy configurations available on the System Preferences > Network > Advanced > Proxies tab.

    You can change these settings by using networksetup command. First, display the list of available network adapters:

    networksetup -listallnetworkservices
    

    To configure and enable the localhost as HTTP and HTTPS proxies:

    networksetup -setwebproxy "Wi-fi" 127.0.0.1 8888
    networksetup -setsecurewebproxy "Wi-fi" 127.0.0.1 8888
    

    To disable the HTTP and HTTPS proxies:

    networksetup -setwebproxystate "Wi-fi" off
    networksetup -setsecurewebproxystate "Wi-fi" off
    

    To display proxy configurations:

    networksetup -getwebproxy "Wi-Fi"
    networksetup -getsecurewebproxy "Wi-Fi"
    

    Check out the help for further options:

    networksetup -help