Script runs via Casper Remote but not as a logout hook in a policy

johnnasset
Contributor

Trying to get some dock management scripts that will trash the logged in users dock at logout and put back in the stock dock via some dockutil commands. The following runs fine via Casper Remote but not as a logout trigger in a policy:

#!/bin/bash


# Set the currently logged in user variable

LoggedInUser=`who | grep console | awk '{print $1}'`

PlistLocation="/Users/$LoggedInUser/Library/Preferences/com.apple.dock.plist";


# Remove all items from the dock
/usr/local/bin/dockutil --remove all "${PlistLocation}" --no-restart;


# Add the dock items in the following order


/usr/local/bin/dockutil --add '/Applications/Launchpad.app' --replacing "Launchpad" --section apps "${PlistLocation}" --no-restart;

/usr/local/bin/dockutil --add '/Applications/Safari.app' --replacing "Safari" --section apps "${PlistLocation}" --no-restart;

/usr/local/bin/dockutil --add '/Applications/Photo Booth.app' --replacing "Photo Booth" --section apps "${PlistLocation}" --no-restart;

/usr/local/bin/dockutil --add '/Applications/iTunes.app' --section apps "${PlistLocation}" --no-restart;

/usr/local/bin/dockutil --add '/Applications/Microsoft Office 2011/Microsoft Word.app' --section apps "${PlistLocation}" --no-restart;

/usr/local/bin/dockutil --add '/Applications/Comic Life.app' --section apps "${PlistLocation}" --no-restart;

/usr/local/bin/dockutil --add '/Applications/GarageBand.app' --section apps "${PlistLocation}" --no-restart;

/usr/local/bin/dockutil --add '/Applications/iMovie.app' --section apps "${PlistLocation}" --no-restart;

/usr/local/bin/dockutil --add '/Applications/Self Service.app' --section apps "${PlistLocation}" --no-restart;

/usr/local/bin/dockutil --add /Applications --view grid --display folder --section others "${PlistLocation}" --no-restart;

/usr/local/bin/dockutil --add /Users/$LoggedInUser/Downloads --view grid --display folder --section others "${PlistLocation}" --no-restart;

/usr/local/bin/dockutil --add /Users/$LoggedInUser/Documents --view grid --display folder --section others "${PlistLocation}" --no-restart;

This is the log in the JSS after the policy fails:

Script result: /Users//Library/Preferences/com.apple.dock.plist does not seem to be a home directory or a dock plist /Users//Library/Preferences/com.apple.dock.plist does not seem to be a home directory or a dock plist /Users//Library/Preferences/com.apple.dock.plist does not seem to be a home directory or a dock plist /Users//Library/Preferences/com.apple.dock.plist does not seem to be a home directory or a dock plist /Users//Library/Preferences/com.apple.dock.plist does not seem to be a home directory or a dock plist /Users//Library/Preferences/com.apple.dock.plist does not seem to be a home directory or a dock plist /Users//Library/Preferences/com.apple.dock.plist does not seem to be a home directory or a dock plist /Users//Library/Preferences/com.apple.dock.plist does not seem to be a home directory or a dock plist /Users//Library/Preferences/com.apple.dock.plist does not seem to be a home directory or a dock plist /Users//Library/Preferences/com.apple.dock.plist does not seem to be a home directory or a dock plist /Users//Library/Preferences/com.apple.dock.plist does not seem to be a home directory or a dock plist /Users//Library/Preferences/com.apple.dock.plist does not seem to be a home directory or a dock plist /Users//Library/Preferences/com.apple.dock.plist does not seem to be a home directory or a dock plist

Seems like the LoggedInUser variable isn't populating properly via policy. Thoughts?

Thanks,
John

1 ACCEPTED SOLUTION

iJake
Valued Contributor

Or

loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`

View solution in original post

5 REPLIES 5

denmoff
Contributor III

try:
LoggedInUser=$(logname)

iJake
Valued Contributor

Or

loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`

johnnasset
Contributor

Thanks @iJake. That worked. @denmoff, I tried your suggestion first but got this in the log:

Script result: /Users/_securityagent/Library/Preferences/com.apple.dock.plist does not seem to be a home directory or a dock plist

Now I need to figure out how to make this run faster. Right now, it's almost 20 seconds from the time I click logout to seeing the login window.

denmoff
Contributor III

good to know. I guess i'll be changing all my scripts now. :-)

bentoms
Release Candidate Programs Tester

Why not lock down the dock via a profile to stop people changing it in the 1st place?