Remove a specific OneDrive volume from the Finder sidebar on a macOS

ClaudiaP
New Contributor II

Hi there,

we are in the process of migrating users from one Office 365 tenant to another, and as part of the process we need to reset all Office apps running on macOS devices enrolled also in a new Jamf Instance. However, I am having some when resetting all Office apps on macOS devices. The old OneDrive volume is still visible in the side bar favorites in Finder. 

I can get everything else working using Office-Reset and an additional line that I am running to remove the OneDrive folder from the user's home directory, but I can't get the old OneDrive volume removed from the side bar in Finder. 

I have even tried uninstalling and reinstalling OneDrive. 

Please note, I only want to remove a specific OneDrive volume from the Finder sidebar  without affecting other favorites using a bash script, so resetting the plist is not an option for me as it will affect other favourite settings.. 

so far I have tried the below two scripts, but neither of them seem to do the trick. 

Has anyone come across something like this before? 

 

 

# Set the name of the OneDrive volume to remove
VOLUME_NAME="OneDrive - CompanayName"

# Use defaults to get the current sidebar favorites
SIDEBAR_FAVORITES=$(defaults read com.apple.sidebarlists favoriteitems)

# Check if the sidebar favorites contain the OneDrive volume
if [[ $SIDEBAR_FAVORITES == *$VOLUME_NAME* ]]; then
# Use sed to remove the OneDrive volume from the sidebar favorites
SIDEBAR_FAVORITES=$(echo "$SIDEBAR_FAVORITES" | sed "s/\"$VOLUME_NAME\"//")

# Use defaults to write the modified sidebar favorites back
defaults write com.apple.sidebarlists favoriteitems -array "$SIDEBAR_FAVORITES"

echo "Successfully removed $VOLUME_NAME from the Finder sidebar."
else
echo "$VOLUME_NAME not found in the Finder sidebar."

 

Second Script:

 

#!/bin/bash# Unmount the OneDrive volume
osascript -e 'tell application "Finder" to eject "OneDrive"'# Remove the OneDrive folder from the Finder sidebar
defaults delete com.apple.sidebarlists favorites | sed '/OneDrive/d' | defaults write com.apple.sidebarlists favorites -data "$(xxd -r -p)"

3 REPLIES 3

AJPinto
Honored Contributor III

Apple removed ~/Library/Preferences/sidebarlists.plist a few years ago. If I am not mistaken this preference now uses ~/Library/Application Support/com.apple.sharedfilelist/com.apple.LSSharedFileList.FavoriteItems.sfl2

 

You may need to reach out to Microsoft for guidance as you cannot really modify a .sfl2 file very easily. I suggest bringing this up in your next Tub or pinging your TAM.

 

 

djsmith83
New Contributor

@ClaudiaP 

What's the line that you are running to remove the OneDrive folder from the user's home directory? Also, did you have any luck with getting the old OneDrive volume removed from the side bar in Finder?

 

We're doing the same thing, migrating users to a new 365 tenant. 

 

Thanks!

 

ClaudiaP
New Contributor II

@djsmith83 

This is the line:

# Remove OneDrive directory from the user's home directory
rm -rf "$HOME/OneDrive - MyCompanyName"

As for the OneDrive volume, I could never get this to work unless I reset it the full Finder PLIST which would also remove other customisation and other volumes already mounted. I opted it for just adding it to the comms so users would just right click and delete the OneDrive volume.

This is the full script I used, this will remove the old OneDrive from the user's home directory and remove any files/settings associated with the old O365/OneDrive tenant. 

I hope this helps :) 

#!/bin/bash

# Remove OneDrive directory from the user's home directory
rm -rf "$HOME/OneDrive - MyCompanyName"

# Remove OneDrive from Finder locations
xattr -d com.apple.FinderInfo "$HOME/Library/Application Support/OneDrive/settings/Business1/OneDriveSyncClientLaunched"
xattr -d com.apple.FinderInfo "$HOME/Library/Application Support/OneDrive/settings/Personal/OneDriveSyncClientLaunched"

echo "The OneDrive directory has been removed from the user's home directory"