I have an AppleScriptObjC Xcode application. Within this application, I've built an updater that checks for updates on startup and will prompt the user to download them. Everything works wonderfully - except for one thing. I need the app to restart when it is updated, so the changes can take effect. I've searched high and low on the internet for this, but I can't figure it out. I cannot to "tell application \"MyApp\" to quit", because Xcode doesn't allow that. Any ideas?
Asked
Active
Viewed 387 times
0
-
1Any reason you're rolling your own update solution instead of using [Sparkle](http://sparkle.andymatuschak.org/)? – Mar 10 '13 at 03:57
-
@duskwuff Not really, but I do like the one I have. Anyway, do you know how to close it? – russellsayshi Mar 10 '13 at 04:02
2 Answers
1
This is an Objective-C-Method to re-launch. May be you can use the idea.
+(void)restart:(id)sender
{
NSString *restartScript = @"while ps -p $1 > /dev/null; do sleep 0.1; done; open \"$2\"";
NSArray *arguments = [NSArray arrayWithObjects:
@"-c", restartScript,
@"",
[NSString stringWithFormat:@"%d",[[NSProcessInfo processInfo] processIdentifier]],
[[NSBundle mainBundle] bundlePath],
nil];
[NSTask launchedTaskWithLaunchPath:@"/bin/sh" arguments:arguments];
[NSApp terminate:self];
}
0
If you just want to quit the app, using the command quit
seems to work fine. If you want it to relaunch (without using Objective-C) you could try starting a separate script just before quitting that does something like this:
delay 2
tell application "Name of Application" to activate
I hope this idea helps.

Ben
- 305
- 4
- 13