folks. In the interest of upping my productivity, I'd like to selectively block or redirect certain websites in blocks of time during the day. I've already got some sites completely blocked in my /etc/hosts, but only having the block active for a certain period is something that has eluded me.

Bonus: I'd also like to be able to block a main domain, but allow for specific pages within. E.g., block, but allow

Thanks for any help you can offer!

migrated from Feb 7 '13 at 21:21

This question came from our site for professional and enthusiast programmers.

  • 1
    You would have two files with configurations "for that time of day", and create a symbolic link from /etc/hosts to one or the other, depending on the time of day, using cron (or Automator on the Mac). worktimeHosts and freetimeHosts... – Floris Feb 7 '13 at 19:05
up vote 2 down vote accepted

Maybe something like this would solve your problem:

  • That does seem to do the job! Do you use it? – Floris Feb 7 '13 at 19:09
  • Wow, this thing is AMAZING. Thank you! – John Hutch Feb 7 '13 at 20:17
  • I don't use it, just played with it briefly a while ago. – smw Feb 7 '13 at 20:19
  • I use it. It's a great way for also setting up an environment for specific tasks. For example, I can bring up my work project list, close down email, etc. – Alan Shutko Feb 7 '13 at 21:32

Although @smw 's answer looks like it might be your solution, there's nothing quite like "rolling your own" - if only for the satisfaction.

Building on my comment above, I am assuming that you can create a /etc/hosts file that gives you the permissions that you want. I am going to call them, as above, worktimeHosts and playtimeHosts. Now you need a script to set one or the other as the active file. This assumes that you have moved your /etc/hosts out of the way...

Create one script:

rm /etc/hosts
ln -s /etc/worktimeHosts /etc/hosts

save it as /usr/bin/getWorking, set permissions to execute chmod 755 /usr/bin/getWorking

Now create a second script:

rm /etc/hosts
ln -s /etc/playtimeHosts /etc/hosts

save it as /usr/bin/getPlaying, set permissions as before

You have to make sure you have permission to do these things to files in /etc...

Now edit the cron table (see for example here)

`crontab -e`

Add a line like this:

00 00 08 * * /usr/bin/getWorking

And another line like this:

00 00 17 * * /usr/bin/getPlaying

I think that will be close to a solution - but I haven't tested this, so play with it and find my errors...

  • Oh man, I love it. @smw 's answer may be ideal, I'm checking it out now, but I may have to do this just cause it's more fun. Hell, I may even be able to use it in conjunction with Concentrate, by using the app instead of a crontab for switching out hosts. Thanks! – John Hutch Feb 7 '13 at 20:16

(Since this is tagged as 'osx' I will assume that an 'OS X-only' solution would be acceptable.)

  1. The ironically-named SelfControl can do this. It will let you define "whitelist" or "blacklist" sites to allow or block, and allows you to set an expiring time-limit. It is free, and source code is available.

  2. There's also MacFreedom which is $10 which does something similar. There is a free trial version available.

(I have used both in the past but am not connected with either.)

Note: If I can offer a word from experience, I would suggest not making a time-limit TOO long, just in case you make a mistake. It is very very difficult to "undo" this before the time limit expires. (Which is a potential problem with any other solution you can just 'undo' if you get bored -- you might!)

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.