andreasgrill / auto-selfcontrol

Small utility to schedule start and stop times of SelfControl
MIT License
305 stars 37 forks source link

Auto-SelfControl

Small utility to schedule start and stop times of SelfControl.

What is it for?

Auto-SelfControl helps you to create a weekly schedule for SelfControl. You can plan for every weekday if and when SelfControl should start and stop.

:warning: Auto-SelfControl is not compatible SelfControl 4. We are currently working on resolving this issue. However, as of now, Auto-SelfControl cannot schedule blocks due to this problem. You might want to consider using Hammer Control, which employs a different approach to address this issue.

Installation

With Homebrew

The easiest way to install Auto-SelfControl is with Homebrew. Install Auto-SelfControl by running the following command in the Terminal:

brew tap andreasgrill/utils
brew install auto-selfcontrol

If you already have SelfControl, start it and backup your blacklist as it might get overridden by Auto-SelfControl.

If you do not have SelfControl already installed on your system, you can install it with Homebrew Cask:

brew install --cask selfcontrol

Manual installation

Download this repository to a directory on your system (e.g., ~/auto-selfcontrol/).

chmod +x auto-selfcontrol

Run from this specific repository

./auto-selfcontrol <config|activate|help>

Optionally create a symlink in your /usr/local/bin folder to access it from anywhere:

sudo ln -s ./auto-selfcontrol /usr/local/bin/auto-selfcontrol

Usage

Edit the time configuration (see Configuration) first:

auto-selfcontrol config

When your block-schedule in config.json is ready, activate it by running:

auto-selfcontrol activate

Important: If you change config.json later, you have to call the auto-selfcontrol activate command again or Auto-SelfControl will not take the modifications into account!

Uninstall

To remove the application (if installed with Homebrew):

brew uninstall auto-selfcontrol

Or, manually, by removing the directory where you installed the files.

sudo unlink /usr/local/bin/auto-selfcontrol
sudo rm -rf /usr/local/etc/auto-selfcontrol
rm -rf ~/auto-selfcontrol

You also need to remove the automatic schedule by executing the following command in the Terminal:

sudo rm /Library/LaunchDaemons/com.parrot-bytes.auto-selfcontrol.plist

Configuration

The following listing shows an example config.json file that blocks every Monday from 9am to 5.30pm and on every Tuesday from 10am to 4pm:

    {
        "username": "MY_USERNAME",
        "selfcontrol-path": "/Applications/SelfControl.app",
        "host-blacklist": [
            "twitter.com",
            "reddit.com"
        ],
        "block-schedules":[
            {
                "weekday": 1,
                "start-hour": 9,
                "start-minute": 0,
                "end-hour": 17,
                "end-minute": 30
            },
            {
                "weekday": 2,
                "start-hour": 10,
                "start-minute": 0,
                "end-hour": 16,
                "end-minute": 0
            }
        ]
    }

The following listing shows another example that blocks twitter and reddit every Sunday from 11pm til Monday 5am, Monday from 9am until 7pm and Monday from 10pm to 11pm:

    {
        "username": "MY_USERNAME",
        "selfcontrol-path": "/Applications/SelfControl.app",
        "host-blacklist":[
            "twitter.com",
            "reddit.com"
        ],
        "block-schedules":[
            {
                "weekday": 7,
                "start-hour": 23,
                "start-minute": 0,
                "end-hour": 5,
                "end-minute": 0
            },
            {
                "weekday": 1,
                "start-hour": 9,
                "start-minute": 0,
                "end-hour": 19,
                "end-minute": 0
            },
            {
                "weekday": 1,
                "start-hour": 22,
                "start-minute": 0,
                "end-hour": 23,
                "end-minute": 0
            }
        ]
    }

Troubleshooting

ImportError: No module named Foundation

If you've installed another version of Python (e.g., using Homebrew), you'll need to run Auto-SelfControl with the original Python installation from macOS:

sudo /usr/bin/python auto-selfcontrol.py

There are also other options, including installing pyobjc on your own Python version (pip install pyobjc). See this thread for alternative solutions.