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!

Permission Denied Error On Npm Install For Yeoman

Yeoman 007

I was trying to create a simple ASP.Net 5 project by using generator like Yeoman on my Mac. The instructions on ASP.Net docs website are simple and easy to follow. However I encountered a permission denied error on npm install for Yeoman.

Npm Error Permission Denied

Initially I thought I was not running an updated npm version so I tried to execute npm upgrade, but it did not work. I also tried to install again npm getting the installing from nodejs.org but the same error occurs.

Looking closely at the log, it was a permission error on a mkdir on /usr/local/bin folder. This was verified when I go to that folder and tried to create a folder but a permission error occurs. Getting closer to the root of the problem!

Wheels

When I looked into the owner and group permissions in the folder, the group owner for node_modules (where the install is targeting the mkdir) is a group name wheel. The group name wheel seems to have been related to the roots of MAC OS X from Unix.

Wheels MacOS Permission

I issued two commands to gain permission to the folder.

sudo chgrp -R admin node_modules

sudo chown -R whoami nodel_modules

After gaining permission to the folder, I once again tried to install Yeoman using npm and the installation went through this time.

Npm yo Ok now

I hope this will save you time if ever you encounter the same problem on your way to trying more ASP.Net 5 samples.

Mirroring On MacBook Causes Page To Shrink

Here is the background

I usually stream movies on my MacBook Pro and then mirror it to my TV to make the viewing much enjoyable, obviously because of the screen size. Here is the setup, my Macbook Pro connected to my TV through a mini display port to HDMI cable. It’s a common setup when you want to connect your laptop to your TV or any display.

The problem?

The problem is when I connect my Macbook Pro to the TV, the Macbook Pro’s display will refresh and you should expect the display to be mirrored to the TV display. Yes, the mirroring happens but page turns into a display shrank into half. The shrank page is also mirrored in the TV display which does not happen to the rest of the open tabs. See below what I mean.

Page Shrank in Half

There are times I preload the movie like in Netflix or other stream sites so you can buffer the whole movie before starting to watch. Then the shrinking happens when you connect it to your TV. Not good.

It worked! Here is the trick

You can alway close and then open again the page that shrank but in case you encounter the issue you can always to do this trick to solve the issue. I tried to move the page, resize the page, minimize/maximize the page but it does not work. Then I tried to open the Developer Tools (Option + Command + I) and then close it.

Chrome Developer Tools Options Bar

It worked, the page goes back to full screen mode without opening or closing the page. Saving anything I buffered in the page. Cool.