mathiasbynens / mathiasbynens/dotfiles
[.macos] Add Finder sidebar (com.apple.sidebarlists) user defaults
Nobody has claimed this yet.
- Dominant language
- Shell
- Stars
- 31.5k
- Forks
- 8.4k
- PR merge metrics
- No merged PRs in 30d
Description
I think I found a way to set Finder sidebar user defaults.
I often wondered why doing `defaults read com.apple.finder > default.txt`, add some sidebar items, `defaults read com.apple.finder > custom.txt` then `diff default.txt custom.txt` didn't show anything.
Googling ‘finder sidebar defaults write’ might have given me [some clues](https://discussions.apple.com/thread/6430038?start=0&tstart=0). As it appears, Finder's sidebar user defaults (`com.apple.sidebarlists`) are different than Finder's user defaults (`com.apple.finder`).
Also, I'll write this as some sort of tutorial, in case some people would like to join us in a world of undocumented boring reverse-engineering.
---

#### Step 1
Let's start by deleting Finder & Finder's sidebar user defaults.
``` shell
defaults delete com.apple.finder; defaults delete com.apple.sidebarlists; killall Finder
```
Let's then remake Finder's sidebar user defaults, tinker around with Finder's sidebar preferences via GUI then [save those [for later comparison]](https://github.com/mathiasbynens/dotfiles/files/404954/default.txt).
``` shell
open -a Finder.app .
```
> [⌘] + [,], ‘Sidebar’ + [Right click] & ‘{ User }’ + [Right click] \* 2
``` shell
killall Finder; defaults read com.apple. > default.txt
```
---

#### Step 2
Let's now invert Finder's sidebar preferences via GUI so that what was enabled becomes disabled and what was disabled becomes enabled [just clicking each item once].
> ```
> open -a Finder.app .
> ```
>
> et cætera,
>
> ```
> killall Finder
> ```
… And then [save those for later comparison](https://github.com/mathiasbynens/dotfiles/files/404952/custom.txt).
```
defaults read com.apple.sidebarlists > custom.txt
```
---

#### Step 3
Let's eventually [compare both user defaults](https://github.com/mathiasbynens/dotfiles/files/404953/diff.txt).
```
diff default.txt custom.txt
```
The following example is just a sample of the results [for the sake of brevity].
```
...
11c11,35
< Name = "All My Files";
---
> Name = Movies;
...
> Name = Music;
...
> Name = Pictures;
...
> Alias = <00000000 008e0003 00010000 d3cb3d58 0000482b 00000000 000266f3 00062d68 0000d3cb 48850000 00000920 fffe0000 00000000 0000ffff ffff0001 00040002 66f3000e 000a0004 006b0076 00700062 000f001c 000d004d 00610063 0069006e 0074006f 00730068 00200053 00530044 0012000a 55736572 732f6b76 70620013 00012f00 00150002 000bffff 0000>;
> CustomItemProperties = {
> "com.apple.LSSharedFileList.Binding" = <646e6962 00000000 01000000 00000000 00000000 00000000 00000000 00000000 00000000 646c6675 02000000 00000000>;
> "com.apple.LSSharedFileList.TemplateSystemSelector" = 1935820909;
> };
> Name = kvpb;
130,132c154,156
< "com.apple.NetworkBrowser.backToMyMacEnabled" = 1;
< "com.apple.NetworkBrowser.bonjourEnabled" = 1;
< "com.apple.NetworkBrowser.connectedEnabled" = 1;
---
> "com.apple.NetworkBrowser.backToMyMacEnabled" = 0;
> "com.apple.NetworkBrowser.bonjourEnabled" = 0;
> "com.apple.NetworkBrowser.connectedEnabled" = 0;
140c164
< ShowEjectables = 1;
---
> ShowEjectables = 0;
142c166
< ShowRemovable = 1;
---
> ShowRemovable = 0;
```
_`diff.txt` sample_
As it can be observed, those are what I was first looking for, though `diff`'s output is just a teeny-tiny part of the hole string.
Looking at `custom.txt`'s first lines tells me that this might be kind of similar to setting Dock's arrays items.
```
{
favoriteitems = {
Controller = CustomListItems;
CustomListItems = (
{
...
```
_`custom.txt` sample_
What I wonder now is how to use `defaults write` to set those with a shell script. I'll tinker a bit more with this and try to come up with a solution. The problem is: what do those hex values mean? Taking a wild guess, I'd say it might be the path the sidebar item links to and maybe the position in the list (though it may be determined by the order it appears in the user defaults). There are other properties I don't get the point of. This looks like a crossover between Finder aliases and Dock items.
**PS:** This is just the beginning. When I'll have figured out how to do this, I will try to add non native items to Finder's sidebar (such as second-party personal directories).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the attached default.txt, custom.txt, and diff.txt files, and the com.apple.sidebarlists values described in the issue. Determine how the Finder sidebar data can be represented in a shell script using defaults write; done means the script reliably configures the requested sidebar items.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- shell
- Domain
- operating-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100