Active and current user ....

Hi,

I need help … While I thought I had found a way to determine, at a specific moment, who were the active (frontmost user) and the current user (the user where a specific script is executed), I am maybe wrong. The statements to check who are these users are:

tell application “Finder” to set activeUserName to do shell script “stat -f ‘%Su’ /dev/console”
tell application “System Events” to set currentUserName to name of current user
get {activeUserName, currentUserName}

While this script gave consistent results and worked perfectly and resisted many tests for many days, this morning things went wrong. While I know, from being in front of the computer, that the active user is User1, the script’s result is now “root”. The current user’s result is OK.

Is my first statement good ?

Thanks in advance.

Robert

I just switched to my other user (User2) and checked the script there. Everythings is OK. I came back to User1 and the result are OK again. “root” disappeared.

Probably the shell script does not check what I call the «active user» but another state. What is the good way to confirm who is the «active user» ?