![mac os bash logged in user mac os bash logged in user](https://b2c-contenthub.com/wp-content/uploads/2021/06/macos-big-sur-terminal-ls-a.jpg)
Su " $loggedInUser " -c '/usr/local/bin/dockutil –add "/Applications/Google Chrome.app" –no-restart ' Su " $loggedInUser " -c '/usr/local/bin/dockutil –add "/Applications/Self Service.app" –no-restart '
![mac os bash logged in user mac os bash logged in user](https://www.howtogeek.com/wp-content/uploads/2019/10/img_5da79219c40ee.jpg)
Su " $loggedInUser " -c '/usr/local/bin/dockutil –add "/Applications/Lock Screen.app" –no-restart ' Su " $loggedInUser " -c '/usr/local/bin/dockutil –add "/Applications/Launchpad.app" –no-restart ' Su – " $loggedInUser " -c '/usr/local/bin/dockutil –remove all –no-restart ' If thenĮcho "Dock already set up for user $loggedInUser, exiting… "Įcho "Dock has not been set up for user $loggedInUser, setting up now… " # Check for the presence of a file created by this script to determine if the Dock has already been configured and if so, exit LoggedInUser= `python -c 'from SystemConfiguration import SCDynamicStoreCop圜onsoleUser import sys username = (SCDynamicStoreCop圜onsoleUser(None, None, None) or ) username = ] (username + "\n") ' ` Determine who the current logged in user is and set that as a variable.But what if you need to run a command as if it’s being run by the current logged in user themselves as part of a policy? One example would be to use a utility like mysides to configure a their sidebar, or if you want to invoke lsregister to register an application so that user doesn’t see something this the first time it’s launched (kudos to on the MacAdmins Slack for pointing out that this tends to be more of an issue for applications living outside /Applications as macOS takes care of those automatically, but I digress):įor a working solution, we need to do two things: Scripts executed this way are run as the root user, which is all well and good if you need to do stuff to the system as a whole with elevated privileges.
MAC OS BASH LOGGED IN USER PRO
One interesting thing about Jamf Pro is that it can execute scripts during a policy run. I’ve already been using this technique for a while but today, thanks to our fantastic Mac Admins community, I’ve learned a little bit more about it, so it might be worth a blog post.