MacOS – Set Finder arranging order by kind via Terminal

findermacos

I know I can easily do this via the Finder's toolbar but I'm currently writing a huge shell script that'll set my future Mac up exactly as I want.

So is there any command to do it like the one to set viewing style ?

Best Answer

To set a default view style use:

defaults write com.apple.Finder FXPreferredViewStyle icnv|Nlsv|clmv|Flwv

with:

icnv: Icon View
Nlsv: List View
clmv: Column View
Flwv: Cover Flow View

To enable this immediately (which probably is not relevant for your shell script) you have to kill the Finder with killall Finder. Some folders might have a different view style set already (via .DS_Store files) while installation. You have to remove those invisible files to adapt your preferred style.

To deal with the group/arrange/sort settings you have to use PlistBuddy and defaults. The relevant key/sub-keys are FXPreferredGroupBy and StandardViewSettings and therein IconViewSettings, ExtendedListViewSettings and ListViewSettings.

Examples:

Arrange by application:

defaults write com.apple.Finder FXPreferredGroupBy Application

Possible values for defaults are none, date, name, kind, Date Added, Date Created, Application etc.

Arrange by kind:

/usr/libexec/PlistBuddy -c "Set :StandardViewSettings:IconViewSettings:arrangeBy kind" ~/Library/Preferences/com.apple.finder.plist

Sort by date added:

/usr/libexec/PlistBuddy -c "Set :StandardViewSettings:ExtendedListViewSettings:sortColumn dateAdded" ~/Library/Preferences/com.apple.finder.plist

Possible values for PlistBuddy are none, date, name, kind, dateAdded, dateCreated etc.

Some combinations of those settings (view style, arrange by, sort by) aren't possible or don't make much sense (depending on your OS).