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.
How to Create a Cron Job to Change the Default Browser
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:
- Minute (by the hour)
- Hour (by 24-hour clock)
- Day (of the month)
- Month
- Day(s) (of the week)
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 (*).
Create a Cron Job to Change Default Browser
Creating a cron job on a Unix/Linux environment is easy.
To list the cron job for the current user:
crontab- l
To edit the cron job for the current user:
crontab -e
What are your work-life balance hacks? Let me know on Twitter @jarednielsen