• 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: Relaunching App Programmatically - Terminal Window Shows up
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Relaunching App Programmatically - Terminal Window Shows up


  • Subject: Re: Relaunching App Programmatically - Terminal Window Shows up
  • From: Michael Ash <email@hidden>
  • Date: Fri, 6 Feb 2009 10:30:13 -0500

On Fri, Feb 6, 2009 at 8:06 AM, email@hidden
<email@hidden> wrote:
> You don't need a helper app for this.
>
> - (void) relaunch
> {
>        int processIdentifier = [[NSProcessInfo processInfo] processIdentifier];
>        NSString *myPath = [NSString stringWithFormat:@"%s",
>        [[[NSBundle mainBundle] executablePath] fileSystemRepresentation]];
>        [NSTask launchedTaskWithLaunchPath:myPath arguments:[NSArray
> arrayWithObject:[NSString stringWithFormat:@"%d",
> processIdentifier]]];
>        [NSApp terminate:self];
> }

If the user has added your application to the Dock permanently, this
will create a new instance of the application with a second icon, then
quit the first, without merging them. The result: one icon for a
non-running application, and a second icon for a running application.
Not good.

My preferred approach is to create a very small tool like this:

int main(int argc, char **argv) {
    char dummy;
    read(STDIN_FILENO, &dummy, 1);
    CFURLRef url = CFURLCreateFromFileSystemRepresentation(NULL,
argv[1], strlen(argv[1]), 0);
    LSOpenCFURLRef(url, NULL);
    return 0;
}

You can then launch it from the parent application, passing the path
to your .app as the only parameter, and giving it an NSPipe for
standard input. When you quit, the pipe closes and the read()
unblocks. It then relaunches your application using LaunchServices,
and you're back in business.

Mike
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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

References: 
 >Relaunching App Programmatically - Terminal Window Shows up (From: Oleg Krupnov <email@hidden>)
 >Re: Relaunching App Programmatically - Terminal Window Shows up (From: "email@hidden" <email@hidden>)

  • Prev by Date: Re: NSTableView and DataSource problem
  • Next by Date: Re: Simple memory problem
  • Previous by thread: Re: Relaunching App Programmatically - Terminal Window Shows up
  • Next by thread: Re: Relaunching App Programmatically - Terminal Window Shows up
  • Index(es):
    • Date
    • Thread