Run a script as the User

Not applicable

I need to be able to have a script run as a user as part of a login policy. The script that I am using is an Applescript. How would I get Casper to call the script at login as the user?

Thanks

Paul Austin

Wachovia/Wells Fargo Desktop Services
704 427-0903

5 REPLIES 5

Not applicable

What you would need to do it in bash is have a script that contains "su $3 -c "osascript -e 'applescript commands'". That is assuming $3 is the user of course.

Applescript might also have some functionality for doing this, but I'm a bash guy so I'm not too sure.

Ryan Harter
UW - Stevens Point
Workstation Developer
715.346.2716

tlarkin
Honored Contributor

the $3 only counts as the current user if casper runs it as a log in hook, otherwise it doesn't work. If you need to script something as root but not as a log in hook the easiest way to get the current logged in user, and I just learned this a few days ago myself (I was using a more complicated method previously) is just put a variable like this

user=/usr/bin/logname

Then call that variable in your script by using $user

So if you trigger it as like a self service policy you could use this method and remember you can invoke shell form apple script and apple script from shell.

-Tom

milesleacy
Valued Contributor

Hey all,

In my testing, logname returns the name of the user executing the command which, when run via policy, is your management account as defined in the JSS for the machine in question.

The following command will return the name of the user logged in at the console:

/usr/bin/who | /usr/bin/grep console | /usr/bin/cut -d " " -f 1

I hope this is helpful.

--
Miles Leacy
Technical Training Manager
Mobile (347) 277-7321

miles at jamfsoftware.com
....................................................................
JAMF Software
1011 Washington Ave. S
Suite 350
Minneapolis, MN 55415
....................................................................
Office: (612) 605-6625
Facsimile: (612) 332-9054
....................................................................
US Support: (612) 216-1296
UK Support +44.(0)20.3002.3907
AU Support +61.(0)2.8014.7469
....................................................................
http://www.jamfsoftware.com

jarednichols
Honored Contributor

I've also used:

user=ls -l /dev/console | cut -d " " -f 4

to return the current user. Then just call $user where you want to use it.

j
---
Jared F. Nichols
Desktop Engineer, Infrastructure & Operations
Information Services Department
MIT Lincoln Laboratory
244 Wood Street
Lexington, Massachusetts 02420
781.981.5436

Not applicable

I don't think I've seen anyone else mention this one yet, but if the system in question is single user based (i.e. only one user logged in at a time), then you can also use:

/usr/bin/users

Patrick Salo
Macs @ Intel Program
Information Technology
Intel Corporation