Re: Checking to see if the app is open before installing
Re: Checking to see if the app is open before installing
- Subject: Re: Checking to see if the app is open before installing
- From: Bill Coderre <email@hidden>
- Date: Thu, 20 Nov 2008 15:44:18 -0800
On Nov 20, 2008, at 1:58 AM, Glover,David wrote:
I’ve been having a look around to find some information on upgrading
an app bundle when it is already open on the machine, but haven’t
really found anything.
I was wondering if it is best practice to check that any apps being
upgraded at install time are closed, and if not, quit the install /
close the open app? Has anybody else come across this, or do
something similar? Is it really necessary, or is it overkill?
I guess it wouldn’t be too difficult to do in a preflight or
preinstall script, but more to the point, is there any point! :o)
So I wrote the code that Apple uses, and yes, it's a good idea for
applications to be quit during an update. Mac OS X Applications store
persistent UI objects in containers called "NIBs" -- menus, windows,
alert panels, etc, are all in NIBs. (Cocoa Nibs, geddit?)
The problem stems from the fact that NIBs do not have to be loaded at
program launch time (and avoiding loading stuff makes programs launch
much faster!). So if your updater changes, say, the NIBs connected
with printing, they might not get loaded before the update happens. So
your old binary executable (which is still running) might end up
calling a new NIB, causing a crash, or misconnected menu items that no
longer work, etc.
Here's the code I wrote for iLife. You might not need something this
complicated.
The distribution JavaScript function
system.applications.fromIdentifier() takes a bundleID and returns non-
null if the program is running. (Documentation: http://tinyurl.com/5afn9d
)
Also, JavaScript has nice strings objects (see "replace", below). (Oh
wait, now I see the documentation for localizedStringWithFormat, and I
could've made that function much simpler!)
// Make sure apps aren't running
var IDArray = [ 'com.apple.iPhoto',
'com.apple.iMovie',
'com.apple.iMovie7',
'com.apple.iMovieHD',
'com.apple.iDVD',
'com.apple.garageband',
'com.apple.iWeb',
];
var NameArray = [ "APPNAME_IPHOTO",
"APPNAME_IMOVIE",
"APPNAME_IMOVIE",
"APPNAME_IMOVIEHD",
"APPNAME_IDVD",
"APPNAME_GB",
"APPNAME_iWeb",
];
var numAppsRunning = 0;
var OneAppRunning = "";
var ManyAppsRunning = "";
for (var index = 0; index < IDArray.length; index++ )
{
if (system.applications.fromIdentifier(IDArray[index]))
{
numAppsRunning++;
OneAppRunning = system.localizedStringWithFormat(NameArray[index]);
ManyAppsRunning = ManyAppsRunning + "\t" + OneAppRunning + "\n";
}
}
if (1 == numAppsRunning)
{
my.result.title =
system.localizedStringWithFormat('TITLE_RUNNING_SINGULAR').replace(/
\^0/gi,OneAppRunning);
my.result.message =
system.localizedStringWithFormat('ERROR_RUNNING');
my.result.type = 'Fatal';
return false;
}
if (1 < numAppsRunning)
{
my.result.title =
system.localizedStringWithFormat('TITLE_RUNNING_PLURAL');
my.result.message = ManyAppsRunning + "\n" +
system.localizedStringWithFormat('ERROR_RUNNING');
my.result.type = 'Fatal';
return false;
}
And here's the localizable strings:
"TITLE_RUNNING_SINGULAR" = "Please quit ^0 before installing iLife.";
"TITLE_RUNNING_PLURAL" = "Please quit the following programs before
installing iLife:";
"ERROR_RUNNING" = "The installer cannot update programs that are
running.";
"APPNAME_IPHOTO" = "iPhoto";
"APPNAME_IMOVIE" = "iMovie";
"APPNAME_IMOVIEHD" = "iMovie HD";
"APPNAME_IDVD" = "iDVD";
"APPNAME_GB" = "GarageBand";
"APPNAME_iWeb" = "iWeb";
As you can see, if there's a single app that needs quitting, the user
sees:
Please quit iMovie before installing iLife.
The installer cannot update programs that are running.
If they have multiple, they see:
Please quit the following programs before installing iLife:
iMovie
iWeb
The installer cannot update programs that are running.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Installer-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden