Block hosts, apps, specific urls (with query string vars!), launch scripts on wake, and generally optimize your productivity and focus
Hyper Focus is a command line tool that watches your computer activity and prevents you from doing distracting things.
In other words, if you are obsessive about personal productivity you can define what you want a productive day to look like and then use Hyper Focus to enforce it.
This is my first/only project in Swift, so feel to submit PRs to fix obvious things that should be better. Here’s what I learned while building this project.
Time is the most valuable + scarce asset. Companies are incentivized to steal your time. Fight back.
brew install iloveitaly/tap/hyper-focus
You can then start the service as a daemon:
brew services start iloveitaly/tap/hyper-focus
Or run it directly:
hyper-focus
# you may want to run as root if your scripts are modifying system files, like /etc/hosts
sudo hyper-focus --configuration ~/.config/focus/config.json
# for debugging/tinkering, it's helpful to tee the logs
LOG_LEVEL=debug hyper-focus 2>&1 | tee hyper-focus.log
When running via a brew service, the logs are located in $(brew --prefix)/var/log/
. You can tail the logs:
tail -f $(brew --prefix)/var/log/hyper_focus.log
Or, download a release build and run it manually.
You’ll need to grant accessibility permissions to the binary, which you can find via brew which hyper-focus
. If scripts you have defined require root access, you’ll also need to grant full disk access to the binary as well.
If permissions get into a weird state, close the app, remove the application from the system permissions list, and then re-add it to the system permissions list.
You may want to run Hyper Focus as root. For instance, if you are modifying the /etc/hosts
file on wake,
you need to run Hyper Focus as root.
Here’s how to do it:
sudo brew services start iloveitaly/tap/hyper-focus
hyper-focus --help
OVERVIEW: A daemon process which helps you focus on your work.
USAGE: hyper-focus [--version] [--configuration <configuration>]
OPTIONS:
--version Print out the version of the application.
-c, --configuration <configuration>
Path to the configuration file
-h, --help Show help information.
If you are running as root, you’ll want to specify the full path to any shell scripts.
/etc/hosts
)/etc/hosts
‘First wake’ means the first time the computer is woken from sleep for the current day.
Having a first wake script allows you to tie into something like clean browsers and todoist scheduler to setup your workspace and todo list for the day.
www.
variants to non-regex block hosts. If you block youtube.com
it will also block www.youtube.com
.https://www.google.com/search?tbm=nws
totbm=nws
query string indicates the google news tab. As long as that query param exists, the pageRegex support is a bit weird: add trailing and leading /
to the block entry to indicate it’s a regex. Think sed
-style.
Example:
{
"block_hosts": [
// normal
"google.com",
// regex!
"/.*google..*/"
]
}
osascript -e 'quit app "App Name"'
).Instead of UI, I’ve opted to a simple HTTP API that can be used to power a Raycast-based UI.
/reload
reload the configuration file without restarting the process/pause
pause the currently running schedule/resume
resume the currently running schedule/override
force a blocking profile to run for a period of time/ping
is this thing on?/configurations
array of names of all blocking profiles. To change the order of the results, change the order of the inputs in your config file.You can hit the API locally for testing using: http localhost:9029/status
swift run
cp ./config.json ~/.config/focus/config.json
git tag v0.1.3 && git push --tags origin HEAD
This is a fun personal tool. Tests are boring, so I didn’t write many of them.
Plus, writing tests in Swift seems to be a massive pain (no dynamic mocks!).