Tech Reflect
  • Home
  • About This Site
  • Contact me
  • Search Icon
“defaults” command tricks

“defaults” command tricks

2018-05-30

If you use the defaults command to set preferences, it’s easy to forget that you ever did. Some implications of this:

  • You could be filling up your drive with logs or slowing your system down
  • You could run into other bugs later that are caused by the default itself
  • An update to an app might not benefit you because the default you set is overriding behavior

Finding defaults

The defaults command has a find subcommand, but I’ve found that people generally aren’t aware of it. Let’s say you set some defaults relating to your trackpad, but don’t know what domain they are in:

defaults find trackpad

Found 3 keys in domain 'Apple Global Domain': {
    "com.apple.trackpad.forceClick" = 0;
    "com.apple.trackpad.scaling" = 3;
    "com.apple.trackpad.scrolling" = "0.75";
}
Found 3 keys in domain 'com.apple.AppleMultitouchTrackpad': {
    Clicking = 0;
    DragLock = 0;
    Dragging = 0;
    FirstClickThreshold = 2;
    ForceSuppressed = 1;
}
Found 1 keys in domain 'com.apple.preference.trackpad': {
    ForceClickSavedState = 0;
}
Found 1 keys in domain 'com.apple.systempreferences': {
    "trackpad.lastselectedtab" = 0;
}

Now you can use “defaults delete” to delete the offending keys or “defaults write” to change them. For the global domain, use “-g” as the domain.

Disabling but not deleting a default

Sometimes you have a default that you want to remember, but you want to disable it for now. One nice way to do this is to use therename command.

defaults rename com.apple.screencapture location _disabled_location

Then, you can just rename it back later rather than deleting it and having to find the default you need to set again. Then, you can usedefaults find _disabled_ and you can find anything you’ve disabled, provide you use a unique prefix.

If it’s a boolean default, you can just set it to -bool false or whatever the opposite setting is.

Keeping track of all defaults

This might be kind of a dumb idea, but add some functions to my .bashrc to track my history of adding defaults.

function defaults-write { defaults write com.my-defaults all -array-add "defaults write $*"; }
export -f defaults-write
function defaults-read { defaults read com.my-defaults all; }
export -f defaults-read
function defaults-delete { defaults delete com.my-defaults; }
export -f defaults-delete

Then I use defaults-write instead of “defaults write” when I want to set a default. This sets the default and writes the command to a domain called com.my-defaults — this can be read easily with defaults-read and the whole domain can be deleted with defaults-delete

Here’s how it works:

defaults-write defaults write com.apple.screencapture foo bar

then:

defaults-read

This outputs:

(     
"defaults write com.apple.screencapture foo bar"
)

This is very primitive but you could imagine making it more powerful. Perhaps it could work like darwinup and keep a track of all defaults commands and then they could all be reversible, since it could keep track of the setting before the defaults command was run.


geeky, macOS tips

Post navigation

NEXT
Ideas for better quality software
PREVIOUS
Keyboard tricks in Dock stacks
Comments are closed.

Get Monthly Updates

Recent Posts

  • Inserting random email sigs in Mail on iOS
  • Keep Instagram open to finish posting…
  • How I predicted the rise of Twitter, barely used it, and amassed 35,000 followers
  • Apple Books 2022, in pictures
  • Killing one bird with two-and-a-half stones in Mac OS X Mail

Categories

  • analog (1)
  • apple career (12)
  • apple inside (19)
  • apple stories (20)
  • bertrand serlet (3)
  • bugs (3)
  • essays (15)
  • geeky (21)
  • interviews (4)
  • iOS tips (4)
  • Mac OS X (7)
  • macOS tips (36)
  • personal (8)
  • predictions (1)
  • products (5)
  • prototypes (6)
  • scott forstall (7)
  • scripting (2)
  • siri (2)
  • steve jobs (16)
  • tim cook (1)
  • workplace (15)

Get Monthly Updates

About cricket


Me with Guiness the owl

25 years in tech. I like to write manifestos. I like to offer interesting tips. I like making fun of things. Everyone copes differently.

My Other Blogs

  • Free Range Parrots
  • Plucky Tree (personal)
© 2025   All Rights Reserved.