Posted on 07-31-2014 11:39 AM
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
Solved! Go to Solution.
Posted on 07-31-2014 12:20 PM
Or
loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
Posted on 07-31-2014 12:10 PM
try:
LoggedInUser=$(logname)
Posted on 07-31-2014 12:20 PM
Or
loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
Posted on 07-31-2014 12:36 PM
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.
Posted on 07-31-2014 12:44 PM
good to know. I guess i'll be changing all my scripts now. :-)
Posted on 07-31-2014 12:51 PM
Why not lock down the dock via a profile to stop people changing it in the 1st place?