• 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 application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Relaunching application


  • Subject: Re: Relaunching application
  • From: David Sinclair <email@hidden>
  • Date: Wed, 5 Jun 2002 08:46:02 -0700

My application needs to be relaunched for some changes to take effect. Is there any way to automate this, or am I stuck showing a notice to the
user and just quitting?

I've done this quite easily in Carbon using the following (Pascal) code. You may be able to do a Cocoa equivalent, or just use Carbon:


launchParam.launchBlockID:= ExtendedBlock; {Launch the new app}
launchParam.launchEPBLength:= ExtendedBlockLen;
launchParam.launchFileFlags:= 0;
launchParam.launchControlFlags:= LaunchContinue+LaunchNoFileFlags;
launchParam.launchAppSpec:= @fileSpec;
launchParam.launchAppParameters:= Nil;

err:= LaunchApplication(@launchParam);

if err<>NoErr then
DoReportError(err);

ExitToShell; {Quit!}


In this case it uses the LaunchContinue flag, which keeps the current app running, so you can do some tidy-up stuff if required before quitting, but if required you can omit that to just switch-launch.

Note that this works as the application isn't actually launched until the next event loop, either locally or after the app quits.

In the above example it is launching a new version of the app, but you can just as easily launch the same app again. Of course, getting the fileSpec of the current app is easy (again Pascal code; Cocoa would be even easier):


function GetApplicationFileSpec(var fileSpec: FSSpec): OSErr;
{Returns a FSSpec of the application itself.}
var
info: ProcessInfoRec;
psn: ProcessSerialNumber;
err: OSErr;
begin
err:= GetCurrentProcess(psn);

info.processInfoLength:= SizeOf(ProcessInfoRec);
info.processName:= Nil;
info.processAppSpec:= @fileSpec;

if err=NoErr then
err:= GetProcessInformation(psn,info);

GetApplicationFileSpec:= err
end;


(Yeah, I bet a lot of you haven't seen Pascal code for years... there are some of us still using Pascal for legacy projects... but even as a Cocoa newbie, Cocoa is much nicer!)

Hope this helps!

--

David Sinclair - email@hidden
http://www.dejal.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Appleevent and thread
  • Next by Date: Re: Sound Recording using Cocoa
  • Previous by thread: Appleevent and thread
  • Next by thread: Window positioning woes
  • Index(es):
    • Date
    • Thread