December 23, 2019
Maintaining a healthy work-life balance is important when you’re a developer. Especially if you work remote. When I set up a new development environment, I create a cron job to change the default browser between work hours and ‘play’ hours. I use Chrome professionally as much of my workflow is built around the Google ecosphere. But I use Firefox as my personal browser (and so should you) for several reasons, the most important being Mozilla’s emphasis on privacy.
Here’s the snippet I use to create a cron job to change the default browser between 8:30AM and 5PM:
30 8 * * 1-5 xdg-settings set default-web-browser google-chrome.desktop 0 17 * * 1-5 xdg-settings set default-web-browser firefox.desktop
Cron jobs follow the ‘5 Star’ format:
* * * * *
From left-to-right, each asterisk corresponds to the following:
In my snippet above, the cron job I created will run at 8:30AM (30 8), but only on weekdays (1-5). This will set my default browser as Chrome.
30 8 * * 1-5 xdg-settings set default-web-browser google-chrome.desktop
At 5PM (0 17), the cron job will run and set my default browser back to Firefox.
0 17 * * 1-5 xdg-settings set default-web-browser firefox.desktop
I leave the day of the month and the month at their default values (*).
Creating a cron job on a Unix/Linux environment is easy.
To list the cron job for the current user:
To edit the cron job for the current user:
What are your work-life balance hacks? Let me know on Twitter @jarednielsen
Want to level up your problem solving skills? I write a weekly newsletter about programming, problem solving and lifelong learning. Join now