Skip to content

Commit bead4d4

Browse files
committed
Move fully to Python3 and add SelfControl 4 support
Add support for the new CLI of SelfControl 4. Support for older SelfControl versions <= 3 is removed to simplify the code. Older Auto-SelfControl versions can still be installed for SelfControl 3 support. The upcoming macOS Monterey 12.3 will remove oob support for Python2. Incorporate separate Python3 module in main module. Resolves: #65
1 parent 306c291 commit bead4d4

7 files changed

+123
-506
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66
*.code-workspace
77

88
# Local History for Visual Studio Code
9-
.history/
9+
.history/
10+
11+
.DS_Store

.vscode/settings.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"python.pythonPath": "/usr/bin/python",
3-
"python.formatting.provider": "autopep8"
2+
"python.linting.enabled": true
43
}

README.md

+28-14
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ You can plan for every weekday if and when SelfControl should start and stop.
1212
1313
## Installation
1414

15+
### Requirements
16+
17+
- Python3 needs to be installed. Check by running the following command in your terminal: `python3 --version`. If Python3 is missing, you should be able to install it through the Xcode developer tools or [Homebrew](https://brew.sh/).
18+
- [SelfControl 4](http://selfcontrolapp.com)
19+
1520
### With Homebrew
1621

1722
The easiest way to install Auto-SelfControl is with [Homebrew](https://brew.sh/). Install Auto-SelfControl by running the following command in the Terminal:
@@ -41,15 +46,33 @@ Optionally create a symlink in your `/usr/local/bin` folder to access it from an
4146

4247
## Usage
4348

44-
Edit the time configuration (see [Configuration](#configuration)) first:
49+
1. Open the configuration file:
50+
51+
To specify when and how Auto-SelfControl should activate, you need to configure a block-schedule in the following configuration file:
52+
53+
~/.config/auto-selfcontrol/config.json
54+
55+
You can also quickly access the configuration file through with the following command:
4556

4657
auto-selfcontrol config
4758

48-
When your block-schedule in [config.json](config.json) is ready, activate it by running:
59+
2. Configure the block schedules
60+
61+
Check and update the configuration file:
62+
63+
- Change the `username` to your current macOS User
64+
- Upda
65+
- Have a look at the [Configuration](#configuration) section
66+
67+
3. Activate and apply the configuration
68+
69+
Changes to the configuration file are not automatically applied. If you want Auto-SelfControl to apply the configuration, you can use the `activate` command:
4970

5071
auto-selfcontrol activate
5172

52-
**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!
73+
If there is an error in your configuration file, the output of the command should give you a hint where to look.
74+
75+
**Important:** If you change your configuration file later, you have to call the `auto-selfcontrol activate` command again or Auto-SelfControl will ignore the modifications. However, changes to an already running block-schedule are ignored until the block-schedule is over.
5376

5477
## Uninstall
5578

@@ -62,10 +85,11 @@ Or, manually, by removing the directory where you installed the files.
6285
sudo unlink /usr/local/bin/auto-selfcontrol
6386
sudo rm -rf /usr/local/etc/auto-selfcontrol
6487
rm -rf ~/auto-selfcontrol
88+
rm -rf ~/.config/auto-selfcontrol
6589

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

68-
sudo rm /Library/LaunchDaemons/com.parrot-bytes.auto-selfcontrol.plist
92+
sudo rm -f /Library/LaunchDaemons/com.parrot-bytes.auto-selfcontrol.plist
6993

7094
## Configuration
7195

@@ -143,13 +167,3 @@ The following listing shows another example that blocks twitter and reddit every
143167
]
144168
}
145169
```
146-
147-
## Troubleshooting
148-
149-
### ImportError: No module named Foundation
150-
151-
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:
152-
153-
sudo /usr/bin/python auto-selfcontrol.py
154-
155-
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).

auto-selfcontrol

+8-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ where:
3232
3333
More instructions at https://github.com/andreasgrill/auto-selfcontrol"
3434

35+
# Check if python3 was found
36+
/usr/bin/python3 --version > /dev/null 2>&1
37+
if [ "$?" -ne 0 ]; then
38+
>&2 echo "ERROR: Python3 was not found. Please install python3, e.g.: brew install python3"
39+
exit 1
40+
fi
41+
3542
if [[ $1 ]]; then
3643
case "$1" in
3744
# Edit configuration file
@@ -52,7 +59,7 @@ if [[ $1 ]]; then
5259
;;
5360
# Install plist config
5461
activate|install)
55-
sudo /usr/bin/python $DIR/auto-selfcontrol.py --install --dir "$(dirname $CONFIG_FILE)"
62+
sudo /usr/bin/python3 $DIR/auto-selfcontrol.py --install --dir "$(dirname $CONFIG_FILE)"
5663
exit 0
5764
;;
5865
-h|--help|help|*)

0 commit comments

Comments
 (0)