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

Re: Re: Launch bundled application before main application


  • Subject: Re: Re: Launch bundled application before main application
  • From: "Julien Jalon" <email@hidden>
  • Date: Sun, 19 Nov 2006 22:00:28 +0100

Much better use:
- (NSString *)pathForResource:(NSString *)name ofType:(NSString *)extension
- (NSString *)executablePath

              NSString *migrationAgentPath = [[[NSBundle mainBundle]
pathForResource:@"Migration Agent" ofType:@"app"] executablePath];

--
Julien

On 11/19/06, Claudio Procida <email@hidden> wrote:

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

_______________________________________________
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


References: 
 >Launch bundled application before main application (From: Claudio Procida <email@hidden>)
 >Re: 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: Launch bundled application before main application
  • Next by Date: window shadow and setAlphaValue bug?
  • Previous by thread: Re: Launch bundled application before main application
  • Next by thread: Re: Re: Re: Launch bundled application before main application
  • Index(es):
    • Date
    • Thread