DIY Rescue-Time, or how I keep myself from wasting time on websites, when I’d rather be working.

About a year ago, I realized that I had a developed a terrible habit. Whenever I was idle, even for a brief moment, I unconsciously visited my favorite news sites. A new browser tab would open, and my fingers would type away. After spending half an hour, an hour, sometimes even a couple of hours on the sites, I’d snap back to realize that I was wasting time. This happened several times every day – I often visited the same site only to discover that I had already read every article of interest.

My solution was to block off any website that I found was too distracting. I wrote the following script and stuck it in my home directory:

#!/bin/bash
if [ "$1" = "free" ]; then
	echo 'Freeing hosts...'
	sudo cp /etc/free_hosts /etc/hosts
	echo '[Done]'
elif [ "$1" = "block" ]; then
	echo 'Blocking hosts...'
	sudo cp /etc/blocked_hosts /etc/hosts
	echo '[Done]'
else
	echo "You can either free or block hosts"
	echo "Usage: "
	echo "	\$switch_hosts free"
	echo "	\$switch_hosts block"
fi

The idea was to replace the host file /etc/hosts with one with a list of blocked websites.
I created two copies of /etc/hosts. One was called /etc/free_hosts and the other was called /etc/blocked_hosts. I then changed /etc/blocked_hosts to look like this:

127.0.0.1	localhost
127.0.0.1	www.reddit.com reddit.com
255.255.255.255	broadcasthost
::1             localhost 
fe80::1%lo0	localhost

Any websites that I did not wish to visit when I was working would simply be redirected to 127.0.0.1. I replaced the default apache homepage on my laptop with a gentle reminder that I had a lot to get done before reading the news.

When I was ready to do work, I opened up a terminal window and typed in:

~/switch_hosts block

Two things happened as a result of this script: suffering from withdrawal, and increased productivity. Initially I tried to visit the blocked sites with even greater frequency than before, only to be presented with my own “get back to work” page. Despite this, I achieved hours more productivity everyday. And after a few days, my frequency attempted site-visits started to go down. I began to concentrate on work for longer stretches of time.

Sometimes it is good to get a small dose of TV, I mean Reddit =)..

~/switch_hosts free

9 Comments so far

  1. Vishal on June 12th, 2011

    Here’s what you do if you have a macbook:
    1) Create a file and paste the code into it.
    => Open a terminal window: Click on spotlight and type in “Terminal”. Open the terminal app.
    => By default, the terminal app places you in your home window. This is fine.
    => Create an empty file called “switch_hosts” by typing in “touch switch_hosts” and hit
    => Edit the switch_hosts file; type in “nano switch_hosts” and hit

    => Copy the code from my blog post for switch_hosts by highlighting it and pressing command c.
    => Paste the copied code into switch_hosts by pressing command v
    => Save switch_hosts by pressing ctrl o and then pressing

    => Exit the nano editor by pressing ctrl x

    2) Change the permissions on the file so it can be executed:
    => Type in “chmod +x switch_hosts” and press .

    3) Run the file by typing in “./switch_hosts”. This should give you some usage instructions.

    4) Make two copies of /etc/hosts
    => Type in “sudo cp /etc/hosts /etc/blocked_hosts” and hit . It will ask you for your password. Type in your password and hit .
    => Type in “sudo cp /etc/hosts /etc/free_hosts” and hit
    . This time it probably won’t ask you for a password since you already typed it in the last time.

    5) Edit /etc/blocked_hosts and add any websites you’d like to block to it. Look at my blog post to see how I’ve blocked off reddit.com.
    => Type in “sudo nano /etc/blocked_hosts” to start editing /etc/blocked_hosts
    => Type in ctrl o to save (overwrite). And then ctrl x to exit.

    If you screw up editing the blocked hosts file, then just repeat Step 4 =).

    6) Start your block script:
    => Type in “cd ~” to go back to your home directory.
    => Type in “./switch_hosts block” to copy /etc/blocked_hosts in place of /etc/hosts. You are now blocking those pages across all browsers.

    7) If you want to unblock the pages:
    => Type in “cd ~” to go back to your home directory
    => Type in “./switch_hosts free” to copy /etc/free_hosts in place of /etc/hosts. Refresh previously blocked pages in the browser and they should start working.

    8\) Type in “exit” in your terminal to end the session. Now simply quit the terminal app by pressing command q.

  2. Dwight on October 11th, 2011

    I’m having some trouble and am wondering if you can help me out. During step 2, when i type in chmod x switch_hosts, it returns “chmod: Invalid file mode: x” Also, if I move to step 4, I cannot type in my password once it prompts me for the password. Any help is appreciated, thanks.

  3. jake on December 7th, 2011

    even though your password isn’t coming up on the screen, your still typing it, the computer just doesn’t display the characters.

  4. Nocturnhabeo on December 7th, 2011

    Hey Dwight you are typing in your pass but you can’t see it when you do. No characters appear on the screen. Also if you want to make sure it works typ chmod 777 switch_hosts instead of chmod x switch_hosts though I believe he had a in front of x which might allow it to work I have never used chmod in this way.

  5. Vishal on December 7th, 2011

    chmod 777 gives full permissions to everyone to do whatever they want with the file. chmod +x simply adds executable permissions.

  6. Anna on December 7th, 2011

    Hi, I was able to block the websites reddit.com and sidereel.com
    but I am trying to block facebook by typing 127.0.0.1 http://www.facebook.com
    and it doesn’t seem to be blocking it. Is there another way I should write it?
    I’ve also tried to block this address http://bookworm.oreilly.com
    but it won’t block either.

  7. autodefenestrator on December 7th, 2011

    (here from a reddit link)

    I still think the method hinted at in xkcd #862 is best:

    http://boingboing.net/2011/02/19/xkcds-productivity-t.html

  8. Vishal on December 7th, 2011

    Here are my entries:
    127.0.0.1 https://www.facebook.com
    127.0.0.1 http://www.facebook.com
    127.0.0.1 facebook.com

    Sometimes it takes a few minutes / refreshes for facebook to get blocked out.

  9. stanley on December 8th, 2011

    ironically, i’m reading this in a lecture

Leave a Reply