I'm trying to create a script that will edit my hosts file to block distracting sites. I'm trying to do so through Python on my mac. I've made the script that edits the host file, but I've only been able to execute it by running
sudo python change_hosts.py
I'd like to be able to run it by calling it from another script. Is there anyway I can package/wrap the script in a way that it can be run without having to go through terminal every time? Can I give it special permission to edit hosts without causing security problems? I read somewhere about an os admin token, is something like that possible in a python script, so that I could enter the password once on boot or something?
Any help appreciated, thanks in advance