Enable Web Proxy On OSX Using Shell Script

Terminal icon osx 150x150

I’ve been using a VPN Tunnel to get me a US ip address so I can watch Netflix. My VPN provider, Ironsocket has a Web proxy I can configure on my browser to enable me to access Netflix and other sites that checks for ip location. Once I’m done watching Netflix I would like to disable the web proxy. It’s very easy in OSX to disable or enable the web proxy in your browser System Preference -> Network -> Advanced -> Proxies, but its easier if it will be done through a shell script. Here is how to enable web proxy on OSX using shell script.

Creating the shell script

You can use any text editor you’d like in OSX. I use vi to create mine. Here is the script:

Shell Script Content

echo "Setting proxy to" $1
networksetup -setwebproxystate Wi-Fi $1
networksetup -setsecurewebproxystate Wi-Fi $1

The important command is the networksetup. Its the system command to use if you want to do anything with your OSX network setup.

I’ve just passed in the protocol I want to configure, this case its only the Web Proxy (-setwebproxystate) and Secure Web Proxy (-setsecurewebproxystate). I also passed in the name of the network adapter I want to configure which (Wi-Fi) and the $1 is just the parameter I passed in from the command line.

Running the shell script

Running the shell script will require you to have Admin rights since this will change a system setting. To run the script as Admin use the command sudo. Here is how I run the script.

Running the script with result

The echo command in the script will be print the last command you made.

That’s it. You now can enable web proxy on OSX using shell script. Hope this helps!

How To Make JSFiddle Default To jQuery Library – Update

In my resolve to not allow my self to go to the same problem of making JSFiddle default to jQuery library , I installed the user script from JohnKPaul to my Chrome browser as an extension. However, after restarting my machine and opening a Chrome window, there is a warning that “the extension is not from Web Store”

Unsupported Extensions Disabled

The warning message when opening again Chrome.

Chrome Allowing Extensions Only From Web store

When you go to chrome://extensions you will see that the extension is now disabled and not working. You cannot enable the extension even if you click “Enable”. No extension means JSFiddle will default back to the “No-Library (pure JS)” library.

Disabled User Script Not From Web Store

User script has been disabled by Chrome. There was no way to enable it.

JSFiddle Default Library No JS

Create Chrome extension for the User Script

When I posted How To Make JSFiddle Default To jQuery Library, it was my plan to convert the user script to a Chrome extension to be able to try and create a Chrome extension myself. I always imagine that someday I can create a Chrome extension and send it to the official Chrome Web Store so everyone can download it. So I think creating a Chrome extension will solve the problem of the user script being disabled since it is not from the Web Store.

Steps on creating the Chrome extension

First, create a manifest.json file. This will contain the information about the extension. The existing extensions you have in your Chrome has their own a manifest.json file. They are located in the Chrome extensions folder C:\Users\[user]\AppData\Local\Google\Chrome\User Data\Default\Extensions.


{
"name": "JSFiddle Default Library to JQuery",
"version": "1",
"manifest_version": 2,
"content_scripts": [{
"js": ["jsfiddle.changedefault.user.js"],
"matches": ["http://jsfiddle.net/*"]
}]
}

Then copy the user script to the same location as the manifest.json.

Extension Folder

How to install the Chrome extension

From the Extensions page, click “Developer Mode”

Chrome extensions Developer mode

Click Load unpacked extension… and then browse to the location of your manifest.json file. Press “Ok” and then you will notice that the extension is now installed and active from the Extensions page.

Testing the new Chrome extension

Now that the extension is installed, go to JSFiddle.Net. The extension made JSFiddle default to jQuery library when you create a new script.

Chrome extension Enabled

JsFiddle Default Library jQuery

Warnings when you restart Chrome

When you restart Chrome you might encounter a warning like the one below.

Disable Developer Mode Extensions Warning

This is a warning to disable developer mode extensions. This is because of the extension added for the user script in developer mode. I will try to make a Chrome extension from the Web Store from this extension in my next post. See you around…