• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Replacing Info.plist programmatically
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Replacing Info.plist programmatically
      • From: Sherm Pendley <email@hidden>
  • Prev by Date: Re: Re: NSWorkspace translation versus finder
  • Next by Date: Modal dialog and the close button
  • Previous by thread: Save a pending NSDocument after setting an application delegate.
  • Next by thread: Re: Replacing Info.plist programmatically
  • Index(es):
    • Date
    • Thread