Re: Restarting application automatically
Re: Restarting application automatically
- Subject: Re: Restarting application automatically
- From: Craig Hunter <email@hidden>
- Date: Fri, 17 Jun 2005 15:41:04 -0400
> Message: 2
> Date: Fri, 17 Jun 2005 09:50:23 -0400
> From: Daniel C?t? <email@hidden>
> Subject: Restarting application automatically
> To: email@hidden
> Message-ID: <email@hidden>
> Content-Type: text/plain; charset="us-ascii"
>
> Hello:
>
> I have a data acquisition program for microscopy that requires a
> restart if the user changes some critical acquisition preferences.
> Currently, I warn the user to restart the application, but I don't do
> it for him. I have seen programs that "restart themselves" and I'd
> like to do that. I have looked for Applescript solutions, but I
> haven't found anything. Anybody knows how I can do that? I was sure
> there was going to be some simple cocoa object/call to send myself
> apple events, but I can't find anything.
>
> Daniel
There are a couple ways to do this. I have gotten the best combination of
timing/reliability using AppleScript and a shell command (and this is from
an AppleScript Studio app, but you can take a similar approach with a pure
Cocoa app):
--
(* if something needs to be done on first launch, do it here *)
-- now, let's launch a new instance of the app and quit the current one
set relaunchPath to "'" & the path of the main bundle &
"/Contents/MacOS/myAppExec" & "'" -- gets the app executable path
do shell script (relaunchPath & " &> /dev/null &")
quit
--
I am basically getting the path to the executable in the app bundle, and
using the shell execute it. This approach will always launch a new instance
of the app even if it's already running (in contrast to "open" or "launch"
which would just make the current instance active). Then the current
instance is quit. It all happens pretty fast.
The important thing is timing, reliability, and avoiding a death spiral of
launch/quit.... I tried quite a few approaches that resulted in the app
repeatedly launching new instances until I could get a force-quit in there
to stop the madness. Other solutions did not work consistently or reliably.
So think through your approach carefully and have a sense of humor when you
test! I arrived at the current approach because it works great every time
for my particular needs.
Craig
--
Dr. Craig Hunter
NASA Langley Research Center
Configuration Aerodynamics Branch
email@hidden
(757) 864-3020
_______________________________________________
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