1

how people know what's possible to be changed via CLI in OSX / macOS if com.apple.finder.plist is a binary file and calling cat command for that file shows only a binary gibberish output?

cat ~/Library/Preferences/com.apple.finder.plist

I've found great option in macOS Sierra:

Keep folders on top when sorting by name

What's the name of it's defaults write so that I can add it into my settings script?

Basically instead of guessing I would like to know where to find all possible options. Does Apple provide it somewhere? I know this site but it's not up to date...

enter image description here

  • idk what the cat command does, but com.apple.finder.plist is a plaintext xml file; ought to be relatively simple to find that command by toggling the pref. Not on Sierra to be able to test. – Tetsujin Sep 21 '16 at 6:37
  • @Tetsujin, The preference file for Finder, as stored on disk, is in fact a binary plist file not an xml file. It's just being displayed as such in the preview in Finder and or an app like TextWrangler. – user3439894 Sep 21 '16 at 15:02
  • ah, OK. Then it would make more sense to view it from TextWrangler... which is what I usually do ;-) – Tetsujin Sep 21 '16 at 15:06
2

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.

  • Just in case it is not obvious: defaults read com.apple.finder will output all the possible settings (130 kB in my case). If you pipe it the output of the command to a file, you have created a nice reference for all options in Finder. – mictter Nov 12 '18 at 17:21
  • @mictter, I first worked with computers back in the punch card days and I'm well aware that terminal command output can be redirected to a file however, that really has nothing to do with the question or answer! – user3439894 Nov 12 '18 at 18:54
  • I wrote it in case someone that came across your perfectly good answer was not aware of it. Isn't precisely that the purpose of this site? – mictter Nov 13 '18 at 13:41
  • @mictter I seem to be running into problems with the command in macOS Mojave. defaults read com.apple.finder _FXSortFoldersFirst return The domain/default pair of (com.apple.finder, _FXSortFoldersFirst) does not exist in prior versions it wasn't a problem and gave a reading. Now, in Mojave, I can't seem to read any of those properties in the Advanced Finder Preferences anymore. Surely they are recorded somewhere, but don't seem to be listed in the com.apple.finder anymore? Any thoughts? – ProGrammer Nov 25 '18 at 11:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .