andreasgrill / auto-selfcontrol

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

Making it work with macOS Monterey 12.3 -- which has python2 removed and supports only python3 #65

Open himanshubabal opened 2 years ago

himanshubabal commented 2 years ago

I had trouble making this work on M1 Macbook with macOS Monterey 12.3. Error -- sudo: /usr/bin/python: command not found Reason -- Apple is removing support for Python2 from this release (12.3) onwards. Solution -- make the code work for Python3

Files location -- /opt/homebrew/bin/auto-selfcontrol and /opt/homebrew/bin/auto-selfcontrol.py

  1. Changing the file "auto-selfcontrol"

    line 55 -- change sudo /usr/bin/python to sudo /usr/bin/python3

  2. Changing the file "auto-selfcontrol.py"

    change print to print() on line 87 and line 132. change has_key to __contains__ on line 343, line 352 and line 361.

edit the get_osx_usernames() function on line 348 by - adding .decode() at the end of line 385 to process the 'b' put by Python3 in front of strings. changing output = subprocess.check_output(["dscl", ".", "list", "/users"]) to output = subprocess.check_output(["dscl", ".", "list", "/users"]).decode()

edit the get_launchscript() function to run Python3 -- <string>/usr/bin/python</string> to <string>/usr/bin/python3</string>

The script runs without any errors after the above changes, however, many other changes might also be required for uncaught exceptions to make the script run from 12.3 onwards. In the meantime, someone please push the above changes to this repo.

Also, the script does run without errors. But it does not work properly -- it does not block (issue 64)

Also auto-selfcontrol install shows

Detected API v2 Start installation of Auto-SelfControl Removed previous installation files Save run configuration Installed

Why does it show API v2. Shouldn't it be API v3 since I am running SelfControl Version 4.0.2 (410)?

andreasgrill commented 2 years ago

Thanks for the help. I've added your recommendations and the ones from #28. My local tests were successful but they are still on a branch. Until we found a solution for #64, it is not of much use anyway. When we solve this issue, we can build a new major version with the changes from the python3 branch.

annnnnk commented 1 year ago

Is there a workaround yet? I can't seem to make auto-selfcontrol work.

cristobal-io commented 1 year ago

I've tried the changes suggested but it doesn't work.

I hope that we can get some solution for this, I can not make it run :(