Skip to content

Instantly share code, notes, and snippets.

@haircut
Last active November 7, 2017 03:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haircut/a57d406996f34402e8ef292ce2f2ba1f to your computer and use it in GitHub Desktop.
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
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