To read/write .plist files, use the defaults
command.
The key that gets set when checking the [√] Keep folders on top when sorting by name check box under Advanced in Finder Preferences is named: _FXSortFoldersFirst
To set this in Terminal (or script) use the following command:
defaults write com.apple.finder _FXSortFoldersFirst -bool YES
To unset, use the following command:
defaults write com.apple.finder _FXSortFoldersFirst -bool NO
Note that in previous OS versions, Finder needed to be restarted using killall Finder
to have some settings, when changed by defaults
, work properly. In macOS 10.12, this is not necessary for this particular setting, however the Finder window does need to be refreshed by some means, e.g. toggling from list view to icon view and back.
If you want to toggle between List view and Icon view in the bash script vs. using killall Finder
after using defaults write ...
, use the following code block:
osascript <<END
tell application "Finder"
set theWindows to every Finder window
repeat with i from 1 to number of items in theWindows
set this_item to item i of theWindows
set theView to current view of this_item
if theView is list view then
set current view of this_item to icon view
else
set current view of this_item to list view
end if
set current view of this_item to theView
end repeat
end tell
END
Note: This method may not work with all setting changes made to Finder, although it works for _FXSortFoldersFirst
, nonetheless killall Finder
may be required for some settings. It's just to early to tell with macOS 10.12.