Website Blocker for macOS (Node.js)
- Browser-agnostic, system-wide blocking by editing
/etc/hosts. - Supports one-off sessions by date/time and recurring daily/weekly schedules.
- Installs a root
launchddaemon that enforces the schedule every minute.
Requirements
- macOS
- Node.js 16+ (uses
Intltime zone support)
Quick Start
- Install globally:
npm install -g website-blocker-macos(or from this repo:npm i -g .) - Create config:
website-blocker init-config - Add domains and schedules with helper commands (below).
- Install daemon (requires admin):
sudo website-blocker install-daemon --config "$HOME/.config/website-blocker/config.json"
Uninstall the daemon:
sudo website-blocker uninstall-daemon
Run once (manual tick) to apply/remove based on current time:
sudo website-blocker tick --config "$HOME/.config/website-blocker/config.json"
Show status (no sudo needed):
website-blocker status --config "$HOME/.config/website-blocker/config.json"
Config File
- Default path:
~/.config/website-blocker/config.json - Specify another path with
--config PATH.
Example (examples/config.example.json):
{
"domains": ["twitter.com", "news.ycombinator.com"],
"sessions": [
{"start": "2025-09-10T09:00:00-04:00", "end": "2025-09-10T17:00:00-04:00"}
],
"recurring": [
{"type": "daily", "start_time": "09:00", "end_time": "17:00", "tz": "America/New_York"},
{"type": "weekly", "days": ["Mon","Tue","Wed","Thu","Fri"], "start_time": "09:00", "end_time": "17:00", "tz": "America/New_York"}
]
}
Notes:
daily/weeklysupport overnight ranges (e.g.,22:00→07:00).- If
tzis omitted, local system time is used. - One-off sessions should use ISO8601 with timezone.
Helper Commands
- Add/remove domains:
website-blocker add-domain twitter.comwebsite-blocker remove-domain twitter.com
- Add recurring rules:
website-blocker add-daily 09:00 17:00 --tz America/New_Yorkwebsite-blocker add-weekly Mon,Tue,Wed,Thu,Fri 09:00 17:00 --tz America/New_York
How it works
- A
launchddaemon runs as root every minute and updates a managed block in/etc/hosts:- Between
# website-blocker-macos STARTand# website-blocker-macos END. - Domains are redirected to
127.0.0.1and::1.
- Between
- When no rule is active, the managed block is removed.
Troubleshooting
- After changing the config, the next minute tick applies it, or run
tickmanually. - Flush DNS cache if needed:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder - If the daemon doesn’t appear to run, check logs:
/var/log/website-blocker-macos.out.log/var/log/website-blocker-macos.err.log
For detailed instructions, see docs/USAGE.md.