Skip to main content
Solved

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

  • July 31, 2014
  • 5 replies
  • 38 views

Forum|alt.badge.img+9

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

Best answer by iJake

Or

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

5 replies

Forum|alt.badge.img+10
  • Valued Contributor
  • July 31, 2014

try:
LoggedInUser=$(logname)


iJake
Forum|alt.badge.img+23
  • Contributor
  • Answer
  • July 31, 2014

Or

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

Forum|alt.badge.img+9
  • Author
  • Contributor
  • July 31, 2014

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.


Forum|alt.badge.img+10
  • Valued Contributor
  • July 31, 2014

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


bentoms
Forum|alt.badge.img+35
  • Hall of Fame
  • July 31, 2014

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