Locally redirecting domains (like with /etc/hosts) during certain hours of the day

2

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 reddit.com, but allow reddit.com/r/javascript

Thanks for any help you can offer!

John Hutch

Posted 2013-02-07T19:02:25.980

Reputation: 21

1You 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... – None – 2013-02-07T19:05:38.887

Answers

2

Maybe something like this would solve your problem: http://www.getconcentrating.com/?

smw

Posted 2013-02-07T19:02:25.980

Reputation: 136

That does seem to do the job! Do you use it? – None – 2013-02-07T19:09:29.153

I don't use it, just played with it briefly a while ago. – None – 2013-02-07T20:19:02.253

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 – 2013-02-07T21:32:53.633

5

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:

#!/bin/bash
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:

#!/bin/bash
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...

Floris

Posted 2013-02-07T19:02:25.980

Reputation: 900

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! – None – 2013-02-07T20:16:11.897

0

(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!)

TJ Luoma

Posted 2013-02-07T19:02:25.980

Reputation: 243