Add item to Finder toolbar with terminal? You can cmd-drag an item to the Finder toolbar to have it there permanently, but is there a way you do this in the Terminal?

The closest I've found is this old thread: http://macscripter.net/viewtopic.php?id=21344

Which suggests something like this:

defaults write com.apple.finder FXToolbarItems -array-add '&lt;dict&gt;&lt;key&gt;file-data&lt;/key&gt;&lt;dict&gt;&lt;key&gt;_CFURLString&lt;/key&gt;&lt;string&gt;"/Applications/Chess.app"&lt;/string&gt;&lt;key&gt;_CFURLStringType&lt;/key&gt;&lt;integer&gt;0&lt;/integer&gt;&lt;/dict&gt;&lt;/dict&gt;'
killall -HUP Finder


.. or perhaps ...

defaults write com.apple.finder FXToolbarItems -array-add '&lt;dict&gt;&lt;key&gt;file-data&lt;/key&gt;&lt;dict&gt;&lt;key&gt;_CFURLString&lt;/key&gt;&lt;string&gt;"/Applications/Chess.app"&lt;/string&gt;&lt;key&gt;_CFURLStringType&lt;/key&gt;&lt;integer&gt;0&lt;/integer&gt;&lt;/dict&gt;&lt;key&gt;item-id&lt;/key&gt;&lt;string&gt;loc%20&lt;/string&gt;&lt;/dict&gt;'
killall -HUP Finder


Neither seem to work. Is there something which works with Yosemite and above?



I notice that if I manually add the Chess app to the Finder toolbar, and then output the finder prefs like so:

defaults read com.apple.finder &gt;&gt; finderprefs


I can see it puts it in like so:

"TB Item Plists" =         {
        7 =             {
            "_CFURLAliasData" = &lt;(lots of hex code)&gt;;
            "_CFURLString" = "file:///Applications/Chess.app";
            "_CFURLStringType" = 15;
        };
    };


So I guess I need to find a way to do that with defaults write



More research suggests adding items programmatically is not advisable: http://prod.lists.apple.com/archives/cocoa-dev/2015/May/msg00212.html

If you know different, I'd love to know...
This is as far as I’ve got, and it’s not working for me on El Capitan (though, that could be something to do with the beta…).

It seems that defaults isn’t comprehensive enough (anymore?) for you to achieve what you want, however you can use PlistBuddy, which on 10.11 is currently found under /usr/libexec/PlistBuddy, to add/remove/edit plist files.  

Here are the two commands you’ll can use to add the _CFURLString and _CFURLStringType:

/usr/libexec/PlistBuddy -c 'Add "NSToolbar Configuration Browser":"TB Item Plists":8:_CFURLString string "file:///Applications/Chess.app"' ~/Library/Preferences/com.apple.finder.plist

/usr/libexec/PlistBuddy -c 'Add "NSToolbar Configuration Browser":"TB Item Plists":8:_CFURLStringType integer 15' ~/Library/Preferences/com.apple.finder.plist


The “8” found in both of the commands above is the array index of the item.  

No _CFURLAliasData is generated (as suggested in several places).  I’ve tried creating an empty _CFURLAliasData, but Finder didn’t populate it.

Another issue is that if I add/remove another item using cmd-drag all the data I’ve added with PlistBuddy gets erased…

Hopefully this information will get someone else partway there.