NOTICE: I am currently working on a standalone version of this project so that it doesn't need to rely on SelfControl. Check it out here.
A script that uses hammerspoon to create schedules for SelfControl.
WARNING: I've built this script to my preferences so there may be a lot of bugs that haven't been caught. Submit an issue or pull request if you do find one though.
Hammer Control uses your password stored in Apple Keychain to automatically fill out SelfControl's prompt to install a helper. Usually you would need to do this manually, but Hammer Control will do it for you so quickly that you will barely notice it. There will be a quick popup indicating that SelfControl started, but it fades away by itself quickly.
Hammer Control has it's own internal clock and it periodically verifies the time with an online source. The user cannot bypass the schedule if they change the local time. When SelfControl starts however, the user can still bypass it with a time skip. When they change the time back, Hammer Control will automatically start another blocking session.
- hammerspoon
brew install hammerspoon
- SelfControl
brew install selfcontrol
Use the installer to setup Hammer Control:
git clone https://github.com/Pandoks/hammer-control.git
cd hammer-control
./install
-
Make hammerspoon directory
mkdir ~/.hammerspoon
-
Clone directory to hammerspoon directory
git clone https://github.com/Pandoks/hammer-control.git ~/.hammerspoon/hammer-control
-
Create
init.lua
for hammerspoontouch ~/.hammerspoon/init.lua
-
Add
require("hammer-control")
to yourinit.lua
fileecho 'require("hammer-control")' | cat - ~/.hammerspoon/init.lua > temp && mv temp ~/.hammerspoon/init.lua
-
Add your password to Apple Keychain
security add-generic-password -a $(whoami) -s hammer-control -w
To update, you can just git pull
inside of ~/.hammerspoon/hammer-control
directory.
git pull
Remember to reload hammerspoon config after pulling.
Hammer Control uses blacklists saved from
SelfControl. You can save a blacklist
(a .selfcontrol
file) by pressing ⌘ + s
while
SelfControl is open. Make sure to remember the
full path to the file starting from your home (~
) directory, because you will need it to
create a schedule.
To create a schedule, create a schedule.json
file in the ~/.hammerspoon/hammer-control
directory. If you want to use the example-schedule.json
as a reference, you can copy it over with
cp ~/.hammerspoon/hammer-control/example-schedule.json ~/.hammerspoon/hammer-control/schedule.json
or copy and paste this into your schedule.json
file:
{
"sunday": [],
"monday": [
{
"start": "23:00",
"end": "23:20",
"blocklist": "~/Desktop/distractions.selfcontrol"
}
],
"tuesday": [],
"wednesday": [],
"thursday": [
{
"start": "03:00",
"end": "04:20",
"blocklist": "~/.hammerspoon/hammer-control/social-media.selfcontrol"
},
{
"start": "23:00",
"end": "23:20",
"blocklist": "~/.hammerspoon/hammer-control/blacklist.selfcontrol"
}
],
"friday": [],
"saturday": []
}
The json
file must contain all of the days of the week in lower case and have their values as
list of objects. Each object has a start
, end
, and blocklist
property. start
and end
are
times in 24 hour format indicating when the scheduled blocking session starts and ends on that
specific day. blocklist
is the file that SelfControl
uses as the blacklist. Ideally, the path to the .selfcontrol
file is absolute, referencing its
location from the home (~
) directory.
NOTE: The hour needs to be 2 digits. 2:00
won't work. 02:00
will work.
- Restarting your system may help