Finder's Side Bar- Hide/Show Favorite items?

Greetings,

Is there a way to hide/show items in the Finder’s side bar’s “Favorites” list. I’m looking to be able to script this on occasion to hide items like Documents, Movies, Music, Pictures …etc …but then be able to show them again later. The reason why I’d like to do this is because on certain tasks for work, I’d only like to focus on a few “Favorite” items, rather than seeing all the standard items. I know I can do this manually but am curious if this is scriptable? Any ideas or insight would be very much appreciated!

-Aaron

1 Like

There is a command line tool called mysides, which allows you to List sidebar favorites items, Append a new item to the end of a list, Insert a new item at the start of the list, and Remove the item (by name).

mysides can be installed in Terminal via Homebrew by using the command [format]brew install mysides[/format]

After mysides has been installed, the first thing I did was to list of all of my Finder sidebar favorites (removing "-> " from each line of the output) and wrote that to file ~/Desktop/My_Sidebar.txt … With this following command. [format]/usr/local/bin/mysides list |sed -E ‘s@-> @@g’ > ~/Desktop/My_Sidebar.txt[/format]
example of an output item: Scripts file:///Library/Scripts/

If “On%20My%20Mac x-finder:OnMyMac” …appears in the ~/Desktop/My_Sidebar.txt file then remove that line from the file.

The next thing I did was to retrieve only the names of all of my Finder sidebar favorites from the ~/Desktop/My_Sidebar.txt file and saved that output to file ~/Desktop/My_Sidebar_Names.txt[format]cut -d " " -f 1 ~/Desktop/My_Sidebar.txt > ~/Desktop/My_Sidebar_Names.txt[/format]
example of an output item: Scripts

Using the file ~/Desktop/My_Sidebar_Names.txt, the next thing I did was to remove all of the names of the items that I want to remain in my Finder sidebar favorites then saved that to file ~/Desktop/My_Sidebar_Names_Remove.txt. This will be the file I use to loop through and remove each item from my Finder sidebar favorites.

Now that you have all your ducks in a row, this following command will remove all of the items of your Finder sidebar favorites that are listed in the ~/Desktop/My_Sidebar_Names_Remove.txt file.[format]cd ~/Desktop/ ;while read line
do /usr/local/bin/mysides remove “$line”
done < My_Sidebar_Names_Remove.txt 2>&1 >/dev/null[/format]

Being that mysides only allows insertions of Finder sidebar favorites at the beginning or end of the list, the only way to restore it back to the way it was is to remove all of Finder sidebar favorites then restore them from your original list (~/Desktop/My_Sidebar.txt).
[format]cd ~/Desktop/ ;while read line
do /usr/local/bin/mysides remove “$line”
done < My_Sidebar_Names.txt 2>&1 >/dev/null
sleep 1
while read line
do /usr/local/bin/mysides add $line
done < My_Sidebar.txt 2>&1 >/dev/null[/format]

This following visual demonstrates removing some Finder sidebar favorites and restoring my Finder sidebar favorites… Activated by two different keyboard shortcuts.

1 Like

Thanks for the suggestion wch1zpink This looks interesting!

Obviously you don’t need to create the files on your desktop. For example, you can always make a new folder named MySides in your Documents folder (or wherever you want), and create all of your initial text files in that new folder, and name them whatever you want. You would have to tweak the code a little bit though. For example anywhere in the code you were to see “~/Desktop/”, that will obviously need to be changed to “~/Documents/MySides/”

Once you create those initial files, you can just take the last two snippets of code and create a new Automator quick action file for each and add a new Run Shell Script command and paste the code into that and save your new quick action. So you would have one new Automator quick action file for removing your Finder sidebar items and one new Automator quick action file for restoring your Finder sidebar items.

From there, now all you need to do is assign those 2 new Automator quick actions a keyboard shortcut, in System Preferences. Then from that point on all you need to do is use your new keyboard shortcuts to hide or restore your Finder sidebar items.

2 Likes