Replacing Info.plist programmatically
Replacing Info.plist programmatically
- Subject: Replacing Info.plist programmatically
- From: Claudio Procida <email@hidden>
- Date: Wed, 22 Nov 2006 19:17:05 +0100
I'm trying to edit the app's Info.plist file programmatically.
The code snippet is the following:
- (IBAction)changeHideDockIcon:(id)sender
{
NSString *mainBundlePath = [[NSBundle mainBundle] bundlePath];
// Read the app's Info.plist dictionary
NSDictionary *infoPlistDict = [[NSBundle mainBundle] infoDictionary];
// Change the value of LSUIElement
[infoPlistDict setValue:[NSNumber numberWithBool:[sender state]]
forKey:LSUIElementKey];
NSString *infoPlistPath = [[mainBundlePath
stringByAppendingPathComponent:@"Contents"]
stringByAppendingPathComponent:@"Info.plist"];
NSString *infoPlistBakPath = [[mainBundlePath
stringByAppendingPathComponent:@"Contents"]
stringByAppendingPathComponent:@"Info.plist.bak"];
NSFileManager *fileManager = [NSFileManager defaultManager];
// Move the old Info.plist file to Info.plist.bak
if ([fileManager movePath:infoPlistPath
toPath:infoPlistBakPath
handler:nil])
{
// Save the Info.plist file
if ([infoPlistDict writeToFile:infoPlistBakPath
atomically:YES])
{
// Hack to force the Info.plist to be read:
// touch the app's main bundle
// See <http://www.cocoabuilder.com/archive/message/cocoa/
2003/11/1/85001>
[fileManager changeFileAttributes:[NSDictionary
dictionaryWithObject:[NSDate date]
forKey:NSFileModificationDate]
atPath:mainBundlePath];
// Remove the Info.plist.bak
[fileManager removeFileAtPath:infoPlistBakPath
handler:nil];
}
else
{
// Restore the old Info.plist
[fileManager movePath:infoPlistBakPath
toPath:infoPlistPath
handler:nil];
}
}
else
{
[sender setState:![sender state]];
}
Anyway, the movePath:toPath:handler: and writeToFile:atomically:
calls return NO.
Since Quicksilver.app appears to overwrite its Info.plist file
successfully, I wonder why I get this behavior? Where am I wrong?
TIA,
Claudio
--
Claudio Procida
Emeraldion Lodge
http://www.emeraldion.it
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins (at) lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden