Q: 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
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
Posted on Jan 15, 2013 9:01 AM