Created
May 20, 2021 23:42
-
-
Save Neradoc/0923ac2a5ca82f492a55d412d3a0a906 to your computer and use it in GitHub Desktop.
Generates a SystemConfiguration preferences file without the Circuitpython boards
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Generates a SystemConfiguration preferences file without the Circuitpython boards | |
Removes everything that has an interface in "usbmodem" | |
Creates a "output_preferences.plist" to replace the original with: | |
sudo cp output_preferences.plist /Library/Preferences/SystemConfiguration/preferences.plist | |
Might not work on Big Sur's heightened security. | |
Not tested with a reboot. | |
There might a better way to do that using the defaults command, once the python script has found all the service_id to remove. | |
""" | |
import plistlib | |
preferences_file = "/Library/Preferences/SystemConfiguration/preferences.plist" | |
with open(preferences_file,"rb") as fp: | |
data = plistlib.load(fp) | |
services = list(data['NetworkServices'].keys()) | |
for service_id in services: | |
service = data['NetworkServices'][service_id] | |
name = service['UserDefinedName'] | |
interface = service['Interface']['DeviceName'] | |
keep = not interface.startswith("usbmodem") | |
print(f"{name} ({interface}) - ",end="") | |
if keep: print("Keep") | |
else: print("Remove") | |
if not keep: | |
del data['NetworkServices'][service_id] | |
with open("output_preferences.plist","wb") as fp: | |
plistlib.dump(data,fp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment