Finally I’ve had some time to come back to
this and play around with the su $USER –c option—seemed like a good idea. But
it doesn’t do quite what I want directly, so I used it indirectly.
I want to run the application as root permissions
so it is set up for all users. (I am assuming a multi-user environment). If you
run it as a specified user (su $USER –c) then it seems that everything is done
using that user’s permissions. I want to display the application in the user’s
current language and run the application as root.
So, I am using defaults to grab the first language
from the AppleLanguages key. I don’t really care what the locale is after all, I
only want to know what language the user is currently running in. For example,
if I am working on a machine in a language I am not very familiar with, I
usually switch it to a known one, then change it back to the user’s language. Also,
I would want to see the install completely in a familiar language rather than
in the machine’s locale.
So to get the user’s language at
postflight time I use:
instllLang=`su $USER -c "defaults
read NSGlobalDomain AppleLanguages" | tr -d ' \n\(\)\"' | awk -F,
'{print $1}'`
(hopefully that comes through, backticks
quotes and all…)
It gives me the language id, and I pass
that to the program.
Seems to work on tiger and leopard so far…
I’ll test it some tomorrow.
:)
From: Bill Coderre
[mailto:email@hidden]
Sent: Monday, March 31, 2008 4:09
PM
To: Lisa Weimer
Cc: ☁☁☁☁☁ EXTERNAL
installer list ☁☁☁☁☁ list ☁☁☁☁☁
Subject: Re: language packagemaker
is running in?
On Mar 31, 2008, at 1:47 PM, St鰨ane
Sudre wrote:
On Mar 31, 2008, at 7:41 PM, Lisa Weimer wrote:
Thanks so much for getting back to me St鰨ane,
Bill and Bill.
I'm going to try the way of the locale command that Bill Janssen
suggested. I think that is what I am looking for, I will soon find out ;)
I'm trying to maintain a consistent language experience across the
installer.
The problem is the locale that the user is installing in may not be the
same as the one root is in. So we might be running the installer in French or
German. The install requires root-- so the user will click "install"
and then they are prompted for their password. The application installs and all
the pre/postflight scripts are run (as root).
During postflight we launch a small helper application to do some more
setup, but the helper application always launches in English. I am thinking
it's because the locale of root is English.
If I was able to pass the locale of the user running the install into
the helper application when I launch it in postflight, then the helper
application will correctly retrieve the correct localized string and be in the
same language the user is in.
(The app itself uses localization functions mentioned by Bill Coderre,
and knows how to display the correct strings)
If we run it through ARD, then of course there are no
problems--everything is done silently and correctly with no confusing language
jumps.
I'll let you know how it goes. If you have any more ideas now
that I have told you a bit more-- please let me know :)
Why not just use:
su $USER -c open
As usual, M Sudre is correct.
Installer postflights have the environment variable $USER set to the
short user ID of the user that double-clicked the installer.
In general, I like to do su $USER -c "command arguments"
especially when affecting user-domain stuff because it runs with the user's own
permissions, reducing security concerns. In some networks, root might not have
access to the user's home directory!