Getting the current user name

I think under Mac OS 9 I could use the command “get owner name” to return the current setting of the “owener name” field.

is there any way under Mac OS X to get the name of the user who is currently logged in? I want to search a mounted server volume for a folder wihich matches the name of the currently logged in user. So it’s just the owner name bit that’s holding me up at the moment

Maybe one/both of these will work.

set user_ to system attribute "USER"
set user_ to do shell script "whoami"

– Rob

both work! thanks!

I think that on long usernames, system attribute “USER”, trunc the name, but not sure

For the sake of clarification, on my system, this returns the short name as entered in the Accounts pref pane. Is that what you are referring to JB? I ask only because truncation might not be the word to use here. :wink:

– Rob

JB, to get the long name you can use one of these scripts

-- set theFullName to do shell script "finger " & (system attribute "USER") & "| grep Login | colrm 1 46"

--set theFullName to do shell script "niutil -readprop . /users/" & (do shell script "whoami") & " realname"

--set usn to do shell script "niutil -readprop . /users/`whoami` realname"
--display dialog usn

(* set cmd to "perl -e "@p = getpwnam `whoami`;" -e 'print "$p[6]";'"
set fullName to (do shell script cmd)
display dialog fullName *)

(* set cmd to "perl -e "@p = getpwnam `whoami`;" -e 'print "$p[6]";'"
do shell script cmd
display dialog result *)

Sorry for the late reply. As Rob mentioned it, I was talking about the short name of the user the one entered in the account pref pane. And it returns the complete short name as exepected, no truncation.

I was wondering if it´s possible to get the current users password as well.
I want the script to use the current user´s user name and password to mount a share, I just can´t seem to find the system attribute for the password. Is it possible to get hold of it?


I hope not!! :shock:

– Rob

Ha ha, ok. I get it. :wink:
Well, I´d like to take the information that a user provides in the login window and use that to mount a share. Shouldn´t be to hard but I can´t make it happen. The username is possible to get through the system attribute “USER” right? So I thought it had to be possible to automaticly take the current user password and use it to mount a volume.