Re: Using NSDictionary to write to /Library/Prefererences
Re: Using NSDictionary to write to /Library/Prefererences
- Subject: Re: Using NSDictionary to write to /Library/Prefererences
- From: Evan Schoenberg <email@hidden>
- Date: Mon, 7 Feb 2005 16:23:42 -0600
On my system, /Library/Preferences has the permissions:
drwxrwxr-x 44 root admin 1496 7 Feb 15:29 Preferences
This means that root can read and write in the directory, and anyone in the admin group can read and write in the directory, but everyone else can only read from the directory. Your program probably does not have permission to be writing out to that location.
Does NSUserDefaults not work from being a loginwindow bundle?
-Evan
www.adiumx.com
On Feb 7, 2005, at 3:18 PM, John Cebasek wrote:
Hi All:
I'm attempting to write into /Library/Preferences to store my preferences. The reason that I need to write to /Library/Preferences, it that I'm a loginwindow bundle and no one has logged in when I need to write to the preferences file.
When I was testing, I was using ~/Library/Preferences to store my file and no errors were reported. Using /Library/Preferences, I get back a NO from writeToFile.
Here's a snippet of the code:
-(void) writeCRYPTOLogonPrefs
{
FunctionTrace trace("Login", "CRYPTOLogonGUI", "writeCRYPTOLogonPrefs");
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMutableDictionary *prefs;
int nWhichPage = [self getDialogPage];
// allocate an NSMutableDictionary to hold our preference data
prefs = [[NSMutableDictionary alloc] init];
//
// Turn the int into a string
//
NSString *sPageNum = [NSString stringWithFormat:@"%d", nWhichPage];
//
// Set which page we're on
//
[prefs setValue:sPageNum forKey:@"PageNum"];
//
// If we're on the hardware page, write out the username
//
if (nWhichPage == HARDWARE_TOKEN_PAGE)
{
[prefs setValue:[userNameTextField stringValue] forKey:@"UserName"];
}
//
// save our preferences list to the /Library/Preferences directory
//
if ([prefs writeToFile:[@"/Library/Preferences/TimHortons.plist" stringByExpandingTildeInPath] atomically: TRUE] == YES)
{
trace.stream() << "Preferences write succeeded." << endl;
}
else
{
trace.stream() << "Why'd it fail?" << endl;
}
[pool release];
}
I left the stringByExpandingTildeInPath because the docs say the string is returned unaltered if there's no '~'.
Any comments on what I'm missing?
John _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden