Tutorial: DIY Website-Blocking Focus Timer on MacOS
There are tons of websites already that cover how to block websites on MacOS using the /etc/hosts file.
The key insight here is that you can treat /etc/hosts like any other file. You can copy it, write another file's contents into it, etc. using the familiar Bash commands cp, mv, etc.
In this script, we use Bash to write additional websites to /etc/hosts, set a timer, and then revert /etc/hosts back to its original contents.
USE THIS SOLUTION AT YOUR OWN RISK. Exercise to the reader: can you think of one thing that a malicious person target in this script? Consider always checking the content of your files before you use sudo.
Source code: https://gist.github.com/dicksontsai/cce96aeebe7c909ee794e42b88ca2c74