Skip to content

Commit

Permalink
Merge branch 'feature/support-selfcontrol-v3'
Browse files Browse the repository at this point in the history
Adds support for SelfControl 3.0 andreasgrill#45
  • Loading branch information
andreasgrill committed May 17, 2020
2 parents b36df69 + 19970bd commit 598af8d
Show file tree
Hide file tree
Showing 5 changed files with 379 additions and 95 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

# Local History for Visual Studio Code
.history/
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"python.pythonPath": "/usr/bin/python",
"python.formatting.provider": "autopep8"
}
78 changes: 58 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Important: SelfControl 3.0 Update
Auto-SelfControl will support SelfControl 3.0 in the coming release, which will be hopefully out in the next few days.

# Auto-SelfControl

Small utility to schedule start and stop times of [SelfControl](http://selfcontrolapp.com).
Expand All @@ -10,22 +7,62 @@ Auto-SelfControl helps you to create a weekly schedule for [SelfControl](http://
You can plan for every weekday if and when SelfControl should start and stop.


## Install
- [SelfControl](http://selfcontrolapp.com) 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](../../archive/master.zip) and copy/extract it to a directory on your Mac (e.g. `~/auto-selfcontrol`).
- Edit the config.json (see [Configuration](#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](config.json). __Important:__ If you change [config.json](config.json) later, you have to call the installation command again or Auto-SelfControl might not start at the right time!
## Installation

### With Homebrew

The easiest way to install Auto-SelfControl is with [Homebrew](https://brew.sh/). Install Auto-SelfControl by running the following command in the Terminal:

brew tap andreasgrill/utils
brew install auto-selfcontrol

If you already have [SelfControl](http://selfcontrolapp.com), start it and **backup your blacklist** as it might get overridden by Auto-SelfControl.

If you do not have [SelfControl](http://selfcontrolapp.com) already installed on your system, you can install it with [Homebrew Cask](https://caskroom.github.io/):

brew cask install 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](#configuration)) first:

auto-selfcontrol config

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

auto-selfcontrol activate

__Important:__ If you change [config.json](config.json) later, you have to call the `auto-selfcontrol activate` command again or Auto-SelfControl will not take the modifications into account!


## 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
```

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
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:
Expand Down Expand Up @@ -55,7 +92,7 @@ The following listing shows an example config.json file that blocks every Monday
]
}
```
- _username_ should be the Mac OS X username.
- _username_ should be the macOS username.
- _selfcontrol-path_ is the absolute path to [SelfControl](http://selfcontrolapp.com).
- _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.
Expand Down Expand Up @@ -103,8 +140,9 @@ The following listing shows another example that blocks twitter and reddit every

### 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:
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 brewed Python (`pip install pyobjc`). [See this thread for alternative solutions](https://stackoverflow.com/questions/1614648/importerror-no-module-named-foundation#1616361).

There are also other options, including installing `pyobjc` on your own Python version (`pip install pyobjc`). [See this thread for alternative solutions](https://stackoverflow.com/questions/1614648/importerror-no-module-named-foundation#1616361).

61 changes: 61 additions & 0 deletions auto-selfcontrol
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env bash
# Auto-SelfControl basic command-line interface

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

# Check if auto-selfcontrol was installed through brew and set the config.json location accordingly
if [[ $DIR == /usr/local/* ]]; then
mkdir -p /usr/local/etc/auto-selfcontrol || true
CONFIG_FILE="/usr/local/etc/auto-selfcontrol/config.json"
else
CONFIG_FILE="$DIR/config.json"
fi

b=$(tput bold)
n=$(tput sgr0)
HELP_TEXT="Auto-SelfControl
Small utility to schedule start and stop times of SelfControl.
Usage: ${b}$(basename "$0") <config|activate|help>${n}
where:
${b}config${n} Open the schedule configuration file in a text
editor to set up weekly parameters
${b}activate${n} Activate the automatic start/stop of SelfControl
according to schedules defined in configuration
${b}help${n} Show this help message
More instructions at https://github.com/andreasgrill/auto-selfcontrol"

if [[ $1 ]]; then
case "$1" in
# Edit configuration file
config|edit|set|conf*)
# If no "config.json" found
if [[ ! -f $CONFIG_FILE ]]; then
curl -L -s "https://raw.githubusercontent.com/andreasgrill/auto-selfcontrol/master/config.json" -o $CONFIG_FILE
echo "Downloaded sample configuration in $CONFIG_FILE"
fi
echo "Opening $CONFIG_FILE"
# Opening with default editor set as $EDITOR
if [[ $EDITOR ]]; then
$EDITOR $CONFIG_FILE
# Or with default GUI text editor (txt files > Open with...)
else
open -t $CONFIG_FILE
fi
;;
# Install plist config
activate|install)
sudo /usr/bin/python $DIR/auto-selfcontrol.py
exit 0
;;
-h|--help|help|*)
echo "$HELP_TEXT"
exit 0
;;
esac
else
echo "$HELP_TEXT"
exit 0
fi
Loading

0 comments on commit 598af8d

Please sign in to comment.