• 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
Re: Launch bundled application before main application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Launch bundled application before main application


  • Subject: Re: Launch bundled application before main application
  • From: Claudio Procida <email@hidden>
  • Date: Sun, 19 Nov 2006 21:10:05 +0100


On 19 nov 2006, at 20:50, Claudio Procida wrote:

I've tried using NSTask. Anyway I get this weird error:

2006-11-19 20:36:27.114 MiniBatteryLogger[15630] *** NSTask: Task create for path /Users/delphine/Sviluppo/SVN/MiniBatteryLogger/ trunk/build/Release/MiniBatteryLogger.app/Contents/Resources/ Migration Agent.app failed: 13, "Permission denied".

Relevant code:

- (void)applicationDidFinishLaunching:(NSNotification *)notif
{
/* Launch Migration Agent if needed */
if (![[defaults objectForKey:MBLDidPerformMigration] boolValue])
{
NSString *migrationAgentPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Migration Agent.app"];

[NSTask launchedTaskWithLaunchPath:migrationAgentPath
arguments:[NSArray arrayWithObject:@""]];
[defaults setObject:[NSNumber numberWithBool:YES]
forKey:MBLDidPerformMigration];
[defaults synchronize];
}
}


I'm using the class method launchedTaskWithLaunchPath:arguments: here, but since I need a blocking call it seems I have to instantiate an object and call [theTask waitUntilExit];

Ok, I'm a dork :) NSTask needs the path to the executable, not the .app wrapper:

- (void)applicationDidFinishLaunching:(NSNotification *)notif
{
/* Launch Migration Agent if needed */
if (![[defaults objectForKey:MBLDidPerformMigration] boolValue])
{
NSString *migrationAgentPath = [[[[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Migration Agent.app"]
stringByAppendingPathComponent:@"Contents"]
stringByAppendingPathComponent:@"MacOS"]
stringByAppendingPathComponent:@"Migration Agent"];


		NSTask *migrationAgentTask = [[NSTask alloc] init];

		[migrationAgentTask setLaunchPath:migrationAgentPath];
		[migrationAgentTask setArguments:[NSArray arrayWithObject:@""]];
		[migrationAgentTask launch];
		[migrationAgentTask waitUntilExit];

		[defaults setObject:[NSNumber numberWithBool:YES]
												  forKey:MBLDidPerformMigration];
		[defaults synchronize];
		[migrationAgentTask release];
	}
}

this works nicely.


-- Claudio Procida Emeraldion Lodge http://www.emeraldion.it


_______________________________________________ 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
  • Follow-Ups:
    • Re: Re: Launch bundled application before main application
      • From: "Julien Jalon" <email@hidden>
References: 
 >Launch bundled application before main application (From: Claudio Procida <email@hidden>)
 >Re: Launch bundled application before main application (From: Claudio Procida <email@hidden>)

  • Prev by Date: Re: IOPMSchedulePowerEvent - laptop lid closed
  • Next by Date: Re: Re: Launch bundled application before main application
  • Previous by thread: Re: Launch bundled application before main application
  • Next by thread: Re: Re: Launch bundled application before main application
  • Index(es):
    • Date
    • Thread