Getting User name [Was Re: Scripting Safari's Preferences window]
Getting User name [Was Re: Scripting Safari's Preferences window]
- Subject: Getting User name [Was Re: Scripting Safari's Preferences window]
- From: KLW <email@hidden>
- Date: Thu, 17 Jul 2003 13:56:46 -0400
>> But I'm afraid that the lack of something as simple as an
AppleScript way to
get the short or long name of the current user, and Apple's recommendation
to use 'do shell script "whoami"', speaks volumes.
Just an FYI to people on the list. The man page for the "whoami" command says:
"The whoami utility has been obsoleted by the id(1) utility,
and is equiv-
alent to ``id -un''. The command ``id -p'' is suggested for normal
interactive use."
Ergo, we should actually be doing like so:
set shortUserName to do shell script "id -un"
or, the AS native way (as pointed out by Lou Serre:
system attribute "USER"
I guess it's time for me to peruse some shell scripts. Of course, in
Unix land, something can be deprecated and still fully available for
another ten years.
Anyway, the id command is more interesting, because it can give you
lots of other information about the user of the script, such as ID,
Group ID, group membership. For example, 'id -p' gives me
uid [my short username]
groups staff wheel admin
Could be a useful way to check if the user has admin privileges, for
example, before attempting to issue a command that requires them.
try
do shell script "id -nG | grep 'admin'" -- If any output is
received, they are admin.
--try will fail if output is blank
set isAdmin to true
on error
set isAdmin to false
end try
I'm probably just displaying my ignorance over a much simpler way to
do this, but here's another way to skin that animal which appears to
have too much skin.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.