Skip to content

 User Defaults Plist → Shell Script converter with Regex filtering

License

Notifications You must be signed in to change notification settings

aerobounce/defaults.sh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 

Repository files navigation

 ds

User Defaults Plist → Shell Script converter.

  • Made for dotfiles
  • Written in Bash
  • Tested on Mojave, Catalina and Big Sur (Although not tested, it should work with older OSes)

asciicast ds demo

Installation

Homebrew

brew install aerobounce/tap/ds

Usage

ds (-d | domain) <(domain | plist-path)>
ds (-c | currentHost) <domain>
ds (-s | save)

ds (-e | --regex) <pattern> (-d | domain) <(domain | plist-path)>
ds (-e | --regex) <pattern> (-c | currentHost) <domain>
ds (-e | --regex) <pattern> (-s | save)

Examples

Regular expression filtering:

### Case Insensitive
$ ds -e '(?i)show' -d "com.apple.finder"

defaults write com.apple.finder "AppleShowAllFiles" -boolean true
defaults write com.apple.finder "ShowHardDrivesOnDesktop" -boolean false
defaults write com.apple.finder "ShowPathbar" -boolean true
...

### Ignore specific keys with an exception
$ ds -e '^(SUEnableAutomaticChecks|(?!SU|NSWindow|NSSplitView|MSApp|NSToolbar).)*$' \
     -d "com.flexibits.fantastical2.mac"

# With this example above, ds skips any keys that start with:
# "SU", "NSWindow", "NSSplitView", "MSApp", "NSToolbar".
# However, "SUEnableAutomaticChecks" is the exception and will not be skipped.

If you came up with other useful expressions, please let me know.

See the preferences of Dock.app on the fly:

$ ds -d com.apple.dock

See the preferences of Music.app on the fly:

$ ds -d com.apple.music

# Dump CurrentHost plist (Note that you just replace `-d` with `-c`, not `-c -d ...`)
$ ds -c com.apple.music

Pipe the result into any command you like:

$ ds -d com.apple.dock | <subl | less | ...>

Export all the user defaults as shell script:

$ ds save

Script that resets preferences of an app while preserving your settings:

#!/usr/bin/env bash

trap 'killall Finder ; open -a Finder >/dev/null 2>&1' EXIT

defaults remove com.apple.finder

defaults write com.apple.finder "AppleShowAllFiles" -boolean true
defaults write com.apple.finder "DisableAllAnimations" -boolean true
...

"Convert" User Defaults?

With defaults, you get either of these:

NeXTStep Format

$ defaults read com.apple.dock

{
    autohide = 1;
    "autohide-delay" = 0;
...

XML Property Lists

$ defaults export com.apple.dock -

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>autohide</key>
    <true/>
    <key>autohide-delay</key>
    <real>0.0</real>
...

With ds, you'll get this:

Shell Script

$ ds -d com.apple.dock

#!/usr/bin/env bash

defaults write com.apple.dock "autohide" -boolean true
defaults write com.apple.dock "autohide-delay" -float 0.0
...