'How can I change Finder's sidebar in macOS Catalina using Bash?

I want to know how I can change the items in the sidebar of Finder in macOS Catalina using a Bash script.

Editing $HOME/Library/Preferences/com.apple.finder.plist or $HOME/Library/SyncedPreferences/com.apple.finder.plist with defaults or PlistBuddy and then restarting Finder (killall Finder) or re-logging the user has no effect on the sidebar.

I think the important information regarding the sidebar is stored in the sfl2 (previously sfl) files (maybe only com.apple.LSSharedFileList.FavoriteItems.sfl2 matters, not sure) at the $HOME/Library/Application\ Support/com.apple.sharedfilelist directory, which can be converted to a human-readable format with plutil -p file_name.sfl2.

Though there seems that currently either no tool exists to edit sfl2 files or the information that I found is deprecated/obsolete (mysides, sfltool, FinderSidebarEditor).

Finder's sidebar



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source