Defaults Write Key in Nested Structure

Hello,


I'm trying to change the SidebarWidth key within the WindowState dictionary which is within the NetworkViewSettings dictionary in the com.apple.finder.plist, but can't figure out how to do it. I've managed to read the NetworkViewSettings dictionary using the "defaults read com.apple.finder NetworkViewSettings -dict" command, but how do I read or write a key within a dictionary nested in that?


If it helps at all, eventually I'll be running this from an AppleScript application, so if there is something built into AppleScript that could do this better then "do shell script" then I'm all for learning. I just figured I would figure out how to do it first in terminal.


MacBook-Pro:~ Default$ defaults read com.apple.finder NetworkViewSettings -dict

{

CustomViewStyleVersion = 1;

WindowState = {

ShowPathbar = 0;

ShowSidebar = 1;

ShowStatusBar = 0;

ShowToolbar = 1;

SidebarWidth = 192;

WindowBounds = "{{455, 251}, {770, 438}}";

};

}


Any ideas?

Thanks for your help!

MacBook Pro (15-inch Mid 2010), Mac OS X (10.7.3)

Posted on Jan 15, 2013 8:47 AM

Reply
Question marked as ⚠️ Top-ranking reply

Posted on Jan 15, 2013 9:01 AM

when you're using the command line defaults utility, the easiest thing to do is to read the entire NetworkViewSettings into a record, modify the record and then write the whole record back out to the plist. trying to modify sub-items is possible, but ugly.


If you want to do it in pure applescript, System Events has a property list suite. That would look like this:


tell application "System Events"

set finderPrefsFile to property list file "~/Library/Preferences/com.apple.Finder.plist"

tell finderPrefsFile

tell property list item "NetworkViewSettings"

tell property list item "WindowState"

set value of property list item "SidebarWidth" to newValue

end tell

end tell

end tell

end tell

2 replies
Sort By: 
Question marked as ⚠️ Top-ranking reply

Jan 15, 2013 9:01 AM in response to AirCaptain150

when you're using the command line defaults utility, the easiest thing to do is to read the entire NetworkViewSettings into a record, modify the record and then write the whole record back out to the plist. trying to modify sub-items is possible, but ugly.


If you want to do it in pure applescript, System Events has a property list suite. That would look like this:


tell application "System Events"

set finderPrefsFile to property list file "~/Library/Preferences/com.apple.Finder.plist"

tell finderPrefsFile

tell property list item "NetworkViewSettings"

tell property list item "WindowState"

set value of property list item "SidebarWidth" to newValue

end tell

end tell

end tell

end tell

Reply

Jun 28, 2016 7:16 AM in response to AirCaptain150

To show the PathBar, the following works:

defaults write com.apple.finder ShowPathbar -bool true


So, by extension, I'd think that you could do the following:

defaults write com.apple.finder SidebarWIdth -int 192


(Note that I changed the type from Boolean (-bool) to integer (-int).

Reply

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Defaults Write Key in Nested Structure

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.