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

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

  • Confirmed - thanks, Ingmar, just what I needed.
    – Scot
    Apr 12 '12 at 17:34

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.

  • Thanks, Adam - thought I'd try who anyway to confirm. As for launchctl list, it returns a Socket is not connected error when in Single User Mode...I wonder if that is enough of a hook?
    – Scot
    Apr 12 '12 at 0:49
  • 1
    Finder isn't always running even in 'normal mode'. It can be quit or replaced with another launcher.
    – user588
    Apr 12 '12 at 0:51
  • If that's consistent Scot, it might be very convenient! Apr 12 '12 at 0:53

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .