Created
January 7, 2022 19:22
-
-
Save ccpost/0e02883e83da973a838255d7791a362a to your computer and use it in GitHub Desktop.
macOS Preferences Dump
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euf -o pipefail | |
dump_domains() { | |
local prefix=$1 | |
local domain=$2 | |
local outputdir=$3 | |
echo "=== dump_domains: prefix='${prefix}', "\ | |
"domain='${domain}', outputdir='${outputdir}'" | |
rm -rf "${outputdir}" | |
mkdir -p "${outputdir}" | |
# Beware: there are spaces in some domains! | |
IFS=$'\n' | |
local domains=( $(${prefix} defaults ${domain} domains | sed 's/, /\'$'\n/g') ) | |
unset IFS | |
domains+=('NSGlobalDomain') | |
echo "Found ${#domains[@]} domains (including global)" | |
for dom in "${domains[@]}"; do | |
${prefix} defaults ${domain} read "${dom}" > "${outputdir}/${dom}" || true | |
done | |
} | |
main() { | |
echo "Auth with sudo for dumping system prefs:" | |
sudo -v | |
dump_domains "sudo" "" "system/default" | |
dump_domains "sudo" "-currentHost" "system/currentHost" | |
dump_domains "" "" "user/default" | |
dump_domains "" "-currentHost" "user/currentHost" | |
# sudo -k | |
echo "Done!" | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment