Skip to main content
Question

Run a script as the User


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

  • 0 replies
  • August 20, 2009

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


Forum|alt.badge.img+31
  • Honored Contributor
  • 2721 replies
  • August 20, 2009

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


Forum|alt.badge.img+23
  • Valued Contributor
  • 512 replies
  • August 24, 2009

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


Forum|alt.badge.img+24
  • Valued Contributor
  • 1892 replies
  • August 24, 2009

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


  • 0 replies
  • August 25, 2009

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings