Detect single-user mode from the command line

Is there a way to detect single-user mode in OSX (Lion, specifically) from the command line?

I've tried who -r, which returns 3 in either standard or single-user mode.

I've also tried nvram boot-args, which does not work either.

Google isn't helping much with this...


$ sysctl -n kern.singleuser
0

It's 1 when booted in single-user mode, 0 when not.


Hmm. We don't have runlevel in OS X*, which would be the easy way. How about identifying something in the output of launchctl list which is not present in single user mode but is present otherwise - com.apple.Finder might be a candidate.

*man who includes: -r Print the current runlevel. This is meaningless on Mac OS X.


In single user mode open directory is not available except by jumping through hoops. You can test the return value of dscl in that case.