I'm developing an application for Mac OS which is used by network administrator to prompt the interactive user to select actions he wants to perform after some software deployment(actions such as restart now, restart later etc.). The dialog will be started remotely from root account(through SSH connection). I have a xml file with localization information from which I want to initialize the dialog GUI and for this I need the top most preferred language of the user but
[[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"]
returns
(es, en, de) when the app is started from interactive user
and
(en) when is started remotely from root account
For getting name of the user I am using bash command 'stat -f\%Su /dev/console' but I can't find how to get preferences for this specific user.
Thanks in advance!
Found a "dirty" solution, the preferences list .GlobalPreferences.plist located in Library/Preferences/ folder of the [user] home directory contains preferred languages of the [user], default home directory is /Users/[user] and if the user is root the path is /var/root/ but this path can be configured, here method -(NSString *)stringByExpandingTildeInPath form NSString can be used to get home directory.
Bellow is the code to get this info:
NSString *interactiveUser = [self getInteractiveUser];
NSString *path = [NSString stringWithFormat: @"~%@/Library/Preferences/.GlobalPreferences.plist", interactiveUser];
path = [path stringByExpandingTildeInPath];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
NSArray *languages = [dict objectForKey:@"AppleLanguages"];
where [self getInteractiveUser] returns interactive user using 'stat -f\%Su /dev/console' command.
Works on Leopard and Lion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With