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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on
11-07-2017
05:43 AM
- last edited on
03-04-2025
09:23 AM
by
kh-richa_mig
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
- Labels:
-
Jamf Pro

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 11-07-2017 05:45 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 11-07-2017 05:50 AM
@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.
