Last active
November 7, 2017 03:57
-
-
Save haircut/a57d406996f34402e8ef292ce2f2ba1f to your computer and use it in GitHub Desktop.
get a list of all non-system users on a Mac in Python
This file contains 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
def getusers(): | |
'''get all non-system users on this Mac''' | |
cmd = ['dscl', '.', '-list', '/Users'] | |
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
out, _ = proc.communicate() | |
userlist = out.splitlines() | |
users = [] | |
filter_out = ['daemon', 'root', 'nobody'] | |
for user in userlist: | |
if not user.startswith('_') and not user in filter_out: | |
users.append(user) | |
return users |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment