Mac OS X: Get the current username and home directory for the current user from the directory service

My application is written in Objective-C. How can I get the username and home directory of the current user in directory services?

More: My Cocoa application gets the current username and home directory with getenv ("USER"), getenv ("HOME"). This does not seem to work correctly if the user logs in through directory services. I do chdir ($ HOME) and then run this command: login -fp $ USER and it rejects it because, I think, the login goes through the directory service to authenticate the user, and his username on this system may not match value of $ USER. Similarly, it may have a home directory specified in directory services that is different from $ HOME.

+3
source share
1 answer

Try NSUserName()and NSHomeDirectory().

+17

Source: https://habr.com/ru/post/1776589/


All Articles