Small utility to schedule start and stop times of SelfControl
Clone or download
andreasgrill Merge pull request #22 from jondeaton/master
Added setup.py for easier installation
Latest commit d5fbb49 Jul 29, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE Initial commit Dec 4, 2015
README.md Fixed typos Jul 23, 2017
auto-selfcontrol.py Python2.7 specification Jul 23, 2017
config.json Simpler default config file. Dec 27, 2015
setup.py Added setup file Jul 23, 2017

README.md

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.

Install

  • SelfControl is required and should be installed in the application directory (however, custom paths are also supported).
  • Start SelfControl and backup your blacklist as it might get overridden by Auto-SelfControl.
  • Download Auto-SelfControl and copy/extract it to a directory on your Mac (e.g. ~/auto-selfcontrol).
  • Edit the config.json (see Configuration first).
  • Open Terminal.app and navigate to the directory. (e.g. cd ~/auto-selfcontrol).
  • Execute /usr/bin/python setup.py install to install the packages required to run Auto-SeltControl.
  • Execute sudo /usr/bin/python auto-selfcontrol.py to install Auto-SelfControl with the block-schedule defined in config.json. Important: If you change config.json later, you have to call the installation command again or Auto-SelfControl might not start at the right time!

Uninstall

  • Delete the installation directory of Auto-SelfControl
  • Execute the following command in the Terminal.app:
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
            }
        ]
    }
  • username should be the Mac OS X username.

  • selfcontrol-path is the absolute path to SelfControl.

  • host-blacklist contains the list of sites that should get blacklisted as a string array. Please note that the blacklist in SelfControl might get overridden and should be backed up before using Auto-SelfControl.

  • block-schedules contains a list of schedules when SelfControl should be started.

    • The weekday settings specifies the day of the week when SelfControl should get started. Possible values are from 1 (Monday) to 7 (Sunday). If the setting is null or omitted the blocking will be scheduled for all week days.
    • start-hour and start-minute denote the time of the day when the blocking should start, while end-hour and end-minute specify the time it should end. The hours must be defined in the 24 hour digit format. If the ending time is before the start time, the block will last until the next day (see example below).

    Please note that it is possible to create multiple schedules on the same day, as long as they are not overlapping. Have a look at the example below.

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 Python using HomeBrew, you'll need to run Auto-SelfControl with the original Python installation from OS X:

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

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