Skip to main content
Question

Script help please - point script to logged in user's home folder


Forum|alt.badge.img+8

Hey gang,

I'm working on packaging up VirtualBox and have most of it done. At the end of the installation, I need to either register the VM with the VirtualBox Manager or open the .vbox file to start the VM which will auto-register. The VM files will live in the logged in user's Library folder and registering the VM populates the VirtualBox Manager app's list of VMs that opens when VirtualBox is launched.

There is a command line tool with VirtualBox for registering the VM:

VBoxManage registervm "/path/to/VirtualBox/Windows/Windows.vbox"

As I mentioned above, these files will live in the logged in user's Library folder (VBox seems to really prefer this location to function properly). When this script runs at the end of my policy, it's looking to our management account's home folder for the files and throws an error in the log. I'm not a good script writer yet so I'm hoping you guys can share with me a way to have it point to the actual logged in user's home folder instead of the Casper management account's home folder. I tried using the $userName variable from Casper and that didn't seem to work but maybe I didn't do it right.

Thanks and appreciate any guidance.

Tom

-------

Tom Anderson
Apple Network Engineer - Institutional Computing
Shenandoah University
1460 University Drive
Winchester, VA 22601

5 replies

Forum|alt.badge.img+20
  • Valued Contributor
  • 732 replies
  • August 19, 2011

Set the current user as a variable and call that variable in the path to the file?

Im not the best coder but it sounds logical to me.
--
Matt Lee, CCA/ACMT/ACPT/ACDT
Senior IT Analyst / Desktop Architecture Team / Apple S.M.E / JAMF Casper Administrator
Fox Networks Group


Forum|alt.badge.img+8
  • Author
  • Contributor
  • 103 replies
  • August 19, 2011

Sounds right to me too and that's the part I'm not sure how to do to be
honest. As you can see, I have some learnin' to do.

Tom

Sent from my iPhone


Forum|alt.badge.img+31
  • Honored Contributor
  • 2721 replies
  • August 19, 2011

Tom (good name by the way)

You can do this several ways:

1) Log in hooks ran by casper use $3 as the current user in variables, log in hooks ran by the login window (apple method) will use $1 as the current logged in user

2) Detect ownership of /dev/console to see who is logged in, if owned by root you are at the login window

3) create and deploy user agents, they run as the user from the get go

-Tom


Forum|alt.badge.img+9
  • Contributor
  • 33 replies
  • December 11, 2012

Here's what I've been using in my scripts...

#Current user
CurrentUser=$(logname)
#Current user home folder
CurrentUserHome=(/Users/"$CurrentUser")

Forum|alt.badge.img+24
  • Valued Contributor
  • 1892 replies
  • December 11, 2012
#Current User
user=`ls -la /dev/console | cut -d " " -f 4`
#Current User home folder - do it this way in case the folder isn't in /Users
userHome=`dscl . -read /users/$user NFSHomeDirectory | cut -d " " -f 2`

Reply


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