Other things on this site...

Research
profile
Recipes

How to schedule regular no-wifi time on a Linux laptop

I'm having problems focusing on my work. It's very difficult to avoid distractions.

One big distraction is something called the World Wide Web... well in my job the most difficult distraction is actually work email - there are lots of different things that distract attention by email. Email is great but it can so easily mean you have no focussed time at all.

I went on a time management course and realised that I should save at least one or two hours per day away from email. I've heard many times, people recommending "No email before noon" or suchlike. I can't imagine being able to go as far as that and also manage meetings etc, but at least I can defend some portion of time.

The problem is not just deciding to stay away from distractions. It's forcing yourself to do it.

I've found one way that helps me: forcing my laptop to be disconnected from the internet between 7am and 9am. It's not much - I mean, many people don't even consider work emails before 9am, though my daily pattern is a bit non-standard. Starting the day this way does help me focus, and make sure I've achieved at least one bit of thoughtful work most days.

Here's how I do it on my linux laptop. I couldn't find any reliable guides for it - I thought there'd be an easy command of some sort. But here's my way:

I tried a few options before this one, including commands that were supposed to auto-run whenever my laptop opened (to check the time and decide whether or not to enable wifi), but there were various problems getting that working, partly because there's a small delay in the "normal" wifi manager connecting, so it's hard to synchronise with that.

In the end I went for a rather brute-force approach: I used "cron" to ensure that once per minute, for every minute between 7am and 9am on a weekday, the "nmcli" command turns off my laptop's networking. Then at 9am it turns it on.

If you don't know cron or crontab, look it up, it's a really common way on linux to schedule commands.

# sudo crontab -e
# seems to need to be in sudo. Not sure why! Probably env vars.
0 9 * * 1-5 /usr/bin/nmcli networking on
* 7-8 * * 1-5 /usr/bin/nmcli networking off

You can see there's a "networking on" command and a "networking off" nmcli command. The numbers at the start of the line specify the day and time - for example "1-5" means Monday to Friday. And " 7-8" means to turn the networking off whenever the hour is 7 or 8, and whenever the minute is anything ("").

This method might seem a bit stupid (why not just turn wifi off once, rather than every 60 seconds?) but actually works very reliably, and has some handy side-effects. It is technically possible for the user (me) to turn wifi back on, and in practice there's often a temptation to do this. Sometimes there's even a good reason! But even if you do, cron will simply come along approx half a minute later and turn it off, meaning that the "rabbit hole" temptation of "oh I'll just check that one thing online" can't lead you off and away from your quiet time.

| IT | Permalink

social