0

defaults read prints out all the preferences for all apps.

defaults write … … can be used to set preferences

But write cannot use the format that comes from read

I would like a way to get all the defaults on demand, save the results, and later restore them all. I don't want to do it with Time Machine, because that would also revert changes I have made in content.

The reason is that Apple keeps changing settings. Seems like almost every week I try to open an image file and find that Apple has changed it from GraphicConverter to Preview, or .csv from LibreOffice to Numbers, or .mp3 from Amadeus to Music. I have many times restored all of these to my preference, and it keeps happening. It's been filed in bugreporter long ago with no response.

I have an AppleCare on this laptop. Might it be worthwhile calling them? When I had a problem with Mai.app, it was weeks of trial and error before the guy declared it "fixed." They have ignored two or more messages saying "no, it is NOT fixed."

Update: Maybe "all the prefs" is an oversimplification of what's in the man page. Point is, it spits a very different format than it can accept.

9
  • For a handful of settings defaults is fine, however your claim "defaults read prints out all the preferences for all apps." is erroneous! I does not print the complete data for the value of any key that is itself a binary plist. In other words, check the output of any key whose value is e.g. {length = $integer, bytes = 0x62706c69 73743030 ... and in that example 62706c69 7374 is bplist. Just keep a Time Machine backup and you can selectively restore various .plist files or read the setting from them to reset a changed setting. Commented Sep 6, 2021 at 0:46
  • 2
    RE: "The reason is that Apple keeps changing settings." -- Sorry I'm not buying that Apple is doing this! It's the various applications involved. As an example, installing and running Script Debugger automatically without explicit permission changes the system defaults for files that open in Script Editor, it it. Yes it's annoying, but going into its preferences and unchecking a couple of checkboxes and it back to the system defaults, in the particular case. Commented Sep 6, 2021 at 0:58
  • I've never done anything with "script debugger" Many times this year, I've double-clicked a .png or .heic and had Preview launch. At least twice, .mp3 has changed from GraphicConverter to Music. And several times, .csv has changed from LibreOffice to Numbers. Every time, I have used GetInfo to change them back (and yes, clicked the change all button). Changing to system default is not a solution. What I want stopped is unrequested changing back to system defaults from what I want.
    – WGroleau
    Commented Sep 6, 2021 at 2:16
  • I have Time Machine backups, but finding the plists that are being inappropriately changed, keeping a list of them, and periodically pulling them all from Time Machine is certainly not a simple solution. Easier just to keep using GetInfo to override whatever (censored) thing keeps tampering with it.
    – WGroleau
    Commented Sep 6, 2021 at 2:17
  • I don't care whether the O.S. or some application is doing it. It should not be happening. The ONLY time Numbers launches is when this (censored) thing happens. So it's not Numbers that's doing it to .csv files. I do play .mp3 in Music. If that's changing their default application, it's puzzling why it happens maybe once a week instead of every time I play a song.
    – WGroleau
    Commented Sep 6, 2021 at 2:23

1 Answer 1

0

defaults read outputs plist keys or entire files in a human-readable form. The output is not designed to be 're-entered'.

Many people do create shell scripts of successive defaults write commands, in order to set up their preferred options after a 'clean' install, or for a new user account, etc. However, it is very difficult, if not impossible, to use the defaults command to create some of the more complex dictionary entries.

To me, Time Machine would seem to be the best way to keep on top of things: if something has changed, go back to when it worked.

The file association to a default application for that file type is stored in one file:

~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist

But bear in mind that preferences are cached, so simply swapping in the file won't work either.

There are utilities that can manage the file-app associations, such as SwiftDefaultApps. https://github.com/Lord-Kamina/SwiftDefaultApps

If something is continually changing your default apps for file type, then that is not normal, and something that needs to be investigated further.

6
  • Whatever it is is intermittent. It’s very often, but as I am editing images and MP3s and opening .CSV daily, I can tell that my changes stick for a while.
    – WGroleau
    Commented Sep 6, 2021 at 14:54
  • The doc for that app says “LaunchServices is permanently looking for invalid or stale associations and removing them.” Obviously, the associations I’ve complained about are valid, but maybe some file somewhere says they are not. But “stale” means what?
    – WGroleau
    Commented Sep 6, 2021 at 14:59
  • Can cached preferences be overcome by using sudo in another account while the “normal” account is not logged in?
    – WGroleau
    Commented Sep 6, 2021 at 15:01
  • There are methods to overcome the caching, such as killing cfprefsd processes.
    – benwiggy
    Commented Sep 6, 2021 at 15:42
  • I examined everything in that .plist and they are all correct at this moment. So I saved a copy in another directory. Figuring out who's changing things without permission will be a challenge, but at least I can restore this file from the copy. I also made the file read-only. Even though I know which file, Time Machine isn't a practical backup, because backups are hourly, and when I double-click a file and the wrong app launches, I have no way of knowing how long ago the bug bit.
    – WGroleau
    Commented Sep 6, 2021 at 20:36

You must log in to answer this question.

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