Block certain sites at certain times of the day

It’s hard not to waste time on the internet.

While I’m working during the day I tend to spend my idle time reading news feeds and posting on message boards. I don’t mind the former, but I inevitably waste far too much time on the latter. It’s become such a habit that it’s difficult to stay away, and once I get sucked in, a good chunk of my day blows by pretty fast.

So I’ve come up with a way to block those time-wasting sites during my work day. This trick is somewhat advanced, but if you follow the directions carefully it shouldn’t be too difficult. These instructions are for Mac OS X 10.5 (Leopard), though you should be able to do something very similar in 10.4 (Tiger).

  1. Open the Finder and choose “Go to Folder…” from the Go menu. Enter /etc/ and click Go.
  2. This step is optional. It’s optional because it’s not necessarily a good idea, as it makes your Mac less secure. However it’s the only easy way I can think of to prevent having to enter your password every time the script runs. If you don’t mind entering your password every time, just skip this step. Otherwise, before you select anything, choose “Get Info” from the File menu. (If a file is selected already, command-click the file to deselect it.) At the bottom of the info window, open the Sharing & Permissions section. Click the tiny lock at the bottom and enter your password. Now click the + (plus) on the bottom-left. Select your user name and click the Select button. Now change the Privilege setting next to your name to Read & Write. Close the info window.
  3. Select the hosts file (in the /etc/ folder) and drag it to your desktop. Since you don’t have permission to move the file, it makes a copy. Rename it to hosts.block (if it asks if you’re sure you want to add an extension, say yes).
  4. Open your hosts.block file in a text editor like TextWrangler (free). I don’t recommend TextEdit for this.
  5. If you’ve edited a hosts file before, this next step is pretty easy. You need to add a line at the end of the file for each site you want to block. At the beginning of the line enter 127.0.0.1 and then a tab, followed by the domain of the site you want to block. The domain is the part after http:// and before the next slash—you know, the .com part. If you wanted to block this site, you’d enter 127.0.0.1 junecloud.com on a line by itself. In some cases you may also want to enter 127.0.0.1 www.junecloud.com on another line. That will make sure the site is blocked whether www is in the address or not.
  6. When you’ve made your changes, save the file.
  7. Move the hosts.block file back into the /etc/ folder. It will tell you it can’t be moved, but you should see an Authenticate button. Click that, and enter your password.
  8. Download these Automator workflows and open them in Automator.
  9. If you followed step 2, delete the text “with administrator privileges” from each workflow. If you skipped step 2, leave them as they are!
  10. For each workflow, choose “Save As Plug-In” from the File menu. Enter Block Sites or Unblock Sites as appropriate, and select “iCal Alarm” from the pop-up menu. Click Save. This will open iCal and create a new event for you. Click Edit to change the time, and set it to repeat every day, or whenever you like. Just remember that any time the Block Sites action runs, you’ll need to run Unblock Sites later on to restore access to those web sites.
  11. Once you’re done you can delete the workflow files from your downloads folder.

That’s it, you’re done! If you skipped steps 2 and 9, you’ll need to enter your password each time the scripts are run. If you followed those steps, it’s completely transparent.

When the sites are blocked, any requests for those sites are redirected to your own computer. If you have a web server running, you’ll see that, otherwise you’ll just get an error that the site can’t be reached.

If you ever need to edit the sites that are blocked, just go to /etc/ and edit your hosts.block file in TextWrangler. (If the site blocking is currently enabled while you’re doing this, edit the hosts file directly instead.) If you need to edit the times blocking is enabled or disabled, open iCal and edit the appropriate events.

Of course if you’re setting this up for yourself, it’s easy to undo—so if you don’t have a lot of willpower, it may not help you. But for me it’s proving an excellent way to break my idle habits. The first day I did this I tried to access the sites I’d blocked several times. The error page was all I needed to remind me though, and I went straight back to work.

I’m sure my days will be far more productive!

Comments

This entry has one comment.

Frank

Frank wrote on May 31, 2008:

Big fan of this! Thanks!

View more

Mac

The Future of Deliveries Deliveries began as a hobby—it was first released as a Dashboard widget named “Apple…

An update on our apps It’s been a while since we shared an update on everything we’re working on. With iOS 15…

Upcoming changes to Deliveries Deliveries 9.2 will be available soon, and we wanted to let you know about some changes…

Deliveries 9 will arrive September 30 Deliveries 9 will be available this Wednesday, September 30, for iPhone, iPad, Apple…