Finding Admin Account Names

Hi All,
I’ve been using the following to find the names of the admin accounts on a computer:

set admins to do shell script "dscl . -read /Groups/admin | /usr/bin/grep GroupMembership"

In particular, for systems with multiple admin accounts, I need the name of the original user account (user 501) or if that’s been deleted, the admin account following that one. In my testing, the result of the above script appears to be a list of names of all admin accounts, in order of creation, so the first name on the list is usually the one I’m looking for, but I’ve found the ordering of the names is inconsistent. Anyone know of a better way to find the name of “user 501” in ASOC. Thanks in advance for any help.


Lion is still under NDA.
You should ask Lion related questions in the appropriate developer forum on

OK. It wasn’t really meant to be a Lion related question, so I went back and edited it.

I found an answer after digging around in UNIX. In case anyone else is looking for a solution,

set theUser to last word of (do shell script "dscacheutil -q user -a uid 501 | grep name:")

does the trick.