Re: Launch bundled application before main application
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