2

I'm trying to update sidebarlist without rebooting computer (in this case they sidebar is updated well after changing values).

My operations are:

Convert into XML

plutil -convert xml1 ~/Library/Preferences/com.apple.sidebarlists.plist

Editing changing things (adding, removing, etc ...)

(using text editor)

Convert into Binary again

plutil -convert binary1 ~/Library/Preferences/com.apple.sidebarlists.plist

Trying to restart Finder in many ways

osascript -e 'quit app "Finder"'
sleep 1
osascript -e 'tell app "Finder" to launch'

killall Finder
killall Finder SystemUIServer
killall -HUP Finder
killall cfprefsd

but the sidebarlist never won't update ...

As I said if I reboot computer, then I see changes.

Any ideas ? Thank you !

P.D. By the way, I'm in Yosemite ... maybe it has something to do

4

NEVER manipulate directly any of the files in ~/Library/Preferences. All preferences are managed by a background process named cfprefsd (short for Core Foundation PREFerences Daemon), which slurps up and caches in RAM the files in ~/Library/Preferences. It used to be that you could often get away with manipulating preference files behind cfprefsd's back, so to speak, but cfprefsd has recently gotten very aggressive about how much it caches.

Instead of editing one of these files, ask cfprefsd for a copy, edit the copy, and then send the contents of the copy back to cfprefsd. Your interface to cfprefsd is the defaults shell command.

For example, to edit the preferences for the com.apple.sidebarlists domain:

defaults read com.apple.sidebarlists > ~/Desktop/sidebarlists.txt
... edit sidebarlists.txt to your heart's content
defaults write com.apple.sidebarlist "$(cat ~/Desktop/sidebarlist.txt)"

You will need to make Finder aware of the changes, so throw in

osascript -e 'tell application "Finder" to quit'
sleep 0.2 # not always necessary
osascript -e 'tell application "Finder" to activate'

Remember to play nicely with other programs. Killing isn't nice, so don't kill anything (especially not cfprefsd) that you don't absolutely need to kill. Don't jerk around with another program's persistent store while it's running. In particular, since cfprefsd is always running, NEVER directly alter the contents of ~/Library/Preferences/*.

If you need to delete a preferences file, the right way is with:

defaults delete its.domain.name

Let cfprefsd worry about getting rid of the file (or, as it is wont to do nowadays, rewriting an essentially empty file on top of it).

The filename ~/Desktop/sidbarlist.txt is, of course, only an example. Use a .plist extension instead of .txt if you prefer. The file will be in NextStep text plist format.

If you prefer some other property list format, use pllist -convert .... Or let the defaults command write it as a .plist file in a format of its choosing with

defaults write ~/Desktop/sidebarlists "$(defaults read com.apple.sidebarlists)"
... edit the file ...
defaults write com.apple.sidebarlists "$(defaults read ~/Desktop/sidebarlists)"

But the important thing is that you keep your copy, the one you edit or otherwise manipulate, out of ~/Library/Preferences. Let defaults worry about communicating with cfprefsd, and let cfprefsd worry about manipulating ~/Library/Preferences.

  • Excellent explanation. Thank you very much. However, doing in that way, the elements won't update in the sidebar ... After doing your way, if I reboot, then I see changes though. – FlamingMoe Dec 11 '14 at 8:48
  • It should update as soon as you quit/restart Finder. It's possible that you may need to order the final steps as: quit Finder, then defaults write..., then activate Finder. (This is to handle the case where Finder updates its defaults while quitting.) – ganbustein Dec 11 '14 at 13:20
  • 1
    Sorry Ganbustein, but even doing in that last way, it's not updating ... is it updating in your system ? I tested in 10.9 and 10.10 – FlamingMoe Dec 13 '14 at 15:56
  • I've been digging into this, and you're right. It isn't updating right away. The theory is sound, except the part where I assumed Finder that was getting the sidebar info directly from cfprefsd. There seems to be some other process that's doing that, and passing the data on to Finder, but I can't identify it. – ganbustein Dec 15 '14 at 5:24
1

Thanks for posting this information - it was very useful in helping me come up with a solution for the sidebar issue within Yosemite.

Our users take their sidebar folders seriously and so we needed to come up with a way of backing up and restoring the contents of the sidebarlists.plist, since Yosemite is so flaky.

I originally tried this method:

Backup:

mkdir -p /Users/Shared/SidebarBackup/

defaults read com.apple.sidebarlists.plist > /Users/Shared/SidebarBackup/SBLbackup.plist

Restore:

osascript -e 'tell application "Finder" to quit'

sleep 0.2

defaults delete com.applesidebarlists.plist

sleep 0.2

defaults write com.apple.sidebarlist "$(cat /Users/Shared/SidebarBackup/SBLbackup.plist)"

osascript -e 'tell application "Finder" to activate'

And found that after restarting the Mac the items were restored but as soon as you launched a Finder window, it would bomb out and you would need to kill finder, delete the plist and then restart before Finder was functional again.

So after much playing around this is the final outcome and it works like a charm:

Backup:

mkdir -p ~/Library/Preferences/Backups

defaults export com.apple.sidebarlists ~/Library/Preferences/Backups/Sidebarlists.plist

Restore:

osascript -e 'tell application "Finder" to quit'

sleep 0.2

defaults delete com.apple.sidebarlists.plist

sleep 0.2

defaults import com.apple.sidebarlists.plist ~/Library/Preferences/Backups/Sidebarlists.plist

sleep 0.2

osascript -e 'tell application "Finder" to activate'

Plan on making this a Casper self-service item (The self-service backup works fine but the restore script doesn't run properly.. If it's not one thing, it's another....)

  • Good plan to place this in self service. Thanks for diving into the difference between defaults import and defaults write – bmike Feb 20 '15 at 13:33
0

I don't think Finder plists update until after restart. So if you're looking to restore sidebar shortcuts, or trash them altogether, you're not going to see the changes until you reboot.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .