• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting the name of the current user
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting the name of the current user


  • Subject: Re: Getting the name of the current user
  • From: "John C. Randolph" <email@hidden>
  • Date: Thu, 30 Aug 2001 20:02:22 -0700

On Thursday, August 30, 2001, at 07:46 PM, Serge Meynard wrote:

Is there an API in Cocoa (or Carbon I guess) to get the name of the current
user under OS X? Searching the apple docs got me nothing.

Try:

NSString *userName = NSUserName();

And if you want the full name, you can use NSFullUserName();

I suppose I could expand the home directory path and extract the last
component using NSString, but that feels like an ugly hack...

That doesn't get you the user's name, it just gets you the name of his home directory. Not necessarily the same thing.

Tip: when searching the docs, don't forget the Foundation and AppKit functions! There's a lot of handy code in there that people tend to re-write because they never looked for it.

-jcr


"Scientology is evil; its techniques are evil; its practice is a serious threat to the community, medically, morally, and socially; and its adherents are sadly deluded and often mentally ill... --Justice Anderson, Supreme Court of Victoria, Australia


References: 
 >Getting the name of the current user (From: Serge Meynard <email@hidden>)

  • Prev by Date: Re: Getting the name of the current user
  • Next by Date: Re: Getting the name of the current user
  • Previous by thread: Re: Getting the name of the current user
  • Next by thread: Re: Getting the name of the current user
  • Index(es):
    • Date
    • Thread