2

I'm writing a login script for OSX 10.8.

I need to know the name of the user who logged in via the Login Window within a login script.

I've tried "whoami", "$USER", and "ls -l /dev/console | awk '{print $3}'", but they all return "root". I assume this is because login scripts run as root, not as the user who authenticated at the Login Window.

Here's an example:

If I login as "bob", or "john", I want the to be able to set a variable to "bob", or "john".

rahmu
  • 20,023
MorganR
  • 123

2 Answers2

1

Do you not want to be using loginhooks for this?

excerpt of that thread

loginhook

This is a place where you can attach a script as the user logs in. You are still the root user for the duration of the script, but immediately after the script ends you become the logging-in user.

HT2420- Mac OS X: Creating a login hook

slm
  • 369,824
0

If you're already using login hooks then the current user should be getting passed as the first parameter to your script. Try $1.

krowe
  • 746