Skip to main content
Question

Onedrive path script/recreate user's Documents folder in finder sidebar


Forum|alt.badge.img+6

I did a test today with the below script in JSS. It creates the onedrive path structure we want for the current user. It worked, and surprisingly did not generate errors due to saved files that were open in the desktop and documents folder.

When I logged in as that user later, the Desktop link was automatically recreated in Finder sidebar for the user, but not the Documents link.

What can I add to this script at the end to force the Documents (and Desktop in case it was a fluke) links back to the user's Finder sidebar?

get current user

currentuser=$(who | grep console | awk '{print $1}')
echo $currentuser

Create onedrive structure

mkdir /Users/$currentuser/OneDrive - Alma College/
mkdir /Users/$currentuser/OneDrive - Alma College/Mac-Files/

Change ownership of that onedrive structure

chown -R $currentuser /Users/$currentuser/OneDrive - Alma College/

Delete Microsoft User Data prior to moving due to illegal characters in filenames

rm -r /Users/$currentuser/Documents/Microsoft User Data

Move the files

mv /Users/$currentuser/Desktop/ /Users/$currentuser/OneDrive - Alma College/Mac-Files/Desktop/
mv /Users/$currentuser/Documents/ /Users/$currentuser/OneDrive - Alma College/Mac-Files/Documents/

Delete finder prefs for user

rm /Users/$currentuser/Library/Preferences/com.apple.sidebarlists.plist
rm /Users/$currentuser/Library/Preferences/com.apple.finder.plist

Create symbolic links

ln -s /Users/$currentuser/OneDrive - Alma College/Mac-Files/Desktop/ /Users/$currentuser/Desktop

ln -s /Users/$currentuser/OneDrive - Alma College/Mac-Files/Documents /Users/$currentuser/Documents

Modify permissions on symbolic links themselves

chown -h $currentuser /Users/$currentuser/OneDrive - Alma College/Mac-Files/Desktop/ /Users/$currentuser/Desktop

chown -h $currentuser /Users/$currentuser/OneDrive - Alma College/Mac-Files/Documents /Users/$currentuser/Documents

Forum|alt.badge.img+6

For some reason when I copied and pasted to my post, it removed the pound signs for my comments in the script. Please ignore that.


Forum|alt.badge.img+8

@mccallister You need to use the code block tag of three consecutive backtick characters (```) before and after any script you want to display in a post, otherwise the display gets mangled.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings