开发者

Mac OS X: Get current username and home directory for current user from Directory Services

开发者 https://www.devze.com 2023-01-26 21:04 出处:网络
My app is written in Objective-C. How can I get the user name and home directory of the currently logged in user through directory services?

My app is written in Objective-C. How can I get the user name and home directory of the currently logged in user through directory services?

Detail: My Cocoa app gets the current username a开发者_开发问答nd home directory with getenv("USER"), getenv("HOME"). Apparently this doesn't work right if the user is logged in through directory services. I am doing a chdir($HOME) and then running this command: login -fp $USER and it rejects it because, I think, login goes through the directory service to authenticate the user, and his username in that system may not be the same as the value of $USER. Likewise, he may have a home directory specified in directory services that is different than $HOME.


Try NSUserName() and NSHomeDirectory().

0

精彩评论

暂无评论...
验证码 换一张
取 消