Skip to main content
Question

folder redirect script

  • June 8, 2021
  • 1 reply
  • 5 views

Forum|alt.badge.img+5

Hi all I have tried this script from jamf it works locally but not being pushed its an AD environment and it to redirect the music folder in documents
does anybody have experience of this

!/bin/bash

Get current logged in username

CURRENTUSER=$(stat -f %Su /dev/console)

Get current AD user name

ADUSER=$(id -F)

Skip redirection if user is localadmin

if [ "$CURRENTUSER" == "xmaadmin" ]; then echo "xma admin, skipping folder redirection" exit
fi

sleep 5

MYDOCDIR="/Volumes/homes$/"$ADUSER"/Documents"

echo $MYDOCDIR

if [ -d "$MYDOCDIR" ]; then echo "$MYDOCDIR is Available!"
else echo "$MYDOCDIR is Empty"

sleep 5

fi

ECHO ----------------- Redirecting Folders ---------------

Wait for OS X to Create Local Homes

sleep 4

ln -Ffhs "/Volumes/homes$/$ADUSER/Documents/My Music" "/Users/$CURRENTUSER/Music/GarageBand"

ECHO ----------------- Completed Script -------------------

$SLEEP 4

killall Finder

exit

1 reply

Forum|alt.badge.img+10
  • Contributor
  • June 11, 2021

It's possible that you will need to run the script in the user's context if running as a jamf policy. prepend the commands with /usr/bin/sudo -u ${CURRENTUSER}

For example: /usr/bin/sudo -u ${CURRENTUSER} ln -Ffhs "/Volumes/homes$/$ADUSER/Documents/My Music" "/Users/$CURRENTUSER/Music/GarageBand"

I haven't tested this but it's worth a shot.