Snapshot and restore macOS preference domains
Adds a round-trip mechanism for macOS system preferences that are not
covered by Homebrew or Mackup (Dock layout, Finder options, global
keyboard shortcuts, input sources, Spaces config, menu-bar clock,
NSGlobalDomain).
sync: `ssr sync` exports each configured domain with `defaults export`
and writes one plist per domain to <backup_dir>/macos-prefs/. Export is
soft-fail per domain so one bad domain doesn't abort the sync. Gated by
SSR_SNAPSHOT_MACOS_PREFS=true (default on).
restore: `ssr restore` replays the snapshot with `defaults import` after
the declarative config/macos-defaults.sh runs, so the snapshot is the
last writer and wins for accepted domains. Before importing, the restore
detects domains that both the snapshot and macos-defaults.sh touch and
prompts interactively:
Domain `com.apple.dock`:
Snapshot will OVERRIDE values set by macos-defaults.sh.
[A]ccept snapshot / [r]eject (keep declarative)? [A/r]:
Non-TTY (launchd, CI) falls back to SSR_PREFS_CONFLICT_DEFAULT (default
"accept"). SSR_ASSUME_YES=true skips all prompts. After import, Dock,
Finder, SystemUIServer and cfprefsd are restarted once.
New config keys: SSR_SNAPSHOT_MACOS_PREFS, SSR_MACOS_PREF_DOMAINS,
SSR_MACOS_PREF_DOMAINS_EXTRA, SSR_PREFS_CONFLICT_DEFAULT, SSR_ASSUME_YES.
ssr-status surfaces the snapshotted-domain count.
README documents the snapshot flow, default domain table, conflict UX,
and the five new config keys.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -13,6 +13,8 @@ source "$SSR_ROOT/lib/brew.sh"
|
||||
source "$SSR_ROOT/lib/mackup.sh"
|
||||
# shellcheck source=../lib/macos.sh
|
||||
source "$SSR_ROOT/lib/macos.sh"
|
||||
# shellcheck source=../lib/macos-prefs.sh
|
||||
source "$SSR_ROOT/lib/macos-prefs.sh"
|
||||
|
||||
ssr::require_macos
|
||||
ssr::load_config
|
||||
@@ -54,4 +56,10 @@ ssr::mackup::restore
|
||||
ssr::macos::open_installed_casks
|
||||
ssr::macos::apply_defaults
|
||||
|
||||
# Import the macOS pref snapshot AFTER the declarative defaults so the
|
||||
# snapshot is the last writer (wins for accepted domains).
|
||||
if [[ "${SSR_SNAPSHOT_MACOS_PREFS:-true}" == "true" ]]; then
|
||||
ssr::macos::prefs_import "$backup_dir"
|
||||
fi
|
||||
|
||||
ssr::ok "ssr restore completed"
|
||||
|
||||
+10
-5
@@ -30,11 +30,16 @@ else
|
||||
echo " last sync: never"
|
||||
fi
|
||||
|
||||
# Surface unmanaged-app count from the last sync, if a report exists.
|
||||
if backup_dir="$(ssr::cloud::backup_dir 2>/dev/null)" \
|
||||
&& [[ -f "$backup_dir/unmanaged-apps.md" ]]; then
|
||||
n="$(grep -cE '^\| \[' "$backup_dir/unmanaged-apps.md" 2>/dev/null || echo 0)"
|
||||
echo " unmanaged: $n app(s) (see $backup_dir/unmanaged-apps.md)"
|
||||
# Surface unmanaged-app count and pref-snapshot summary from the last sync.
|
||||
if backup_dir="$(ssr::cloud::backup_dir 2>/dev/null)"; then
|
||||
if [[ -f "$backup_dir/unmanaged-apps.md" ]]; then
|
||||
n="$(grep -cE '^\| \[' "$backup_dir/unmanaged-apps.md" 2>/dev/null || echo 0)"
|
||||
echo " unmanaged: $n app(s) (see $backup_dir/unmanaged-apps.md)"
|
||||
fi
|
||||
if [[ -d "$backup_dir/macos-prefs" ]]; then
|
||||
n="$(find "$backup_dir/macos-prefs" -name '*.plist' 2>/dev/null | wc -l | tr -d ' ')"
|
||||
echo " prefs snap: $n domain(s) (see $backup_dir/macos-prefs/)"
|
||||
fi
|
||||
fi
|
||||
|
||||
label="${SSR_LAUNCHD_LABEL:-de.surke.ssr.sync}"
|
||||
|
||||
@@ -13,6 +13,8 @@ source "$SSR_ROOT/lib/brew.sh"
|
||||
source "$SSR_ROOT/lib/mackup.sh"
|
||||
# shellcheck source=../lib/apps.sh
|
||||
source "$SSR_ROOT/lib/apps.sh"
|
||||
# shellcheck source=../lib/macos-prefs.sh
|
||||
source "$SSR_ROOT/lib/macos-prefs.sh"
|
||||
|
||||
ssr::require_macos
|
||||
ssr::load_config
|
||||
@@ -54,6 +56,12 @@ if [[ "${SSR_SCAN_UNMANAGED_APPS:-true}" == "true" ]]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
# Snapshot macOS preference domains so they can be restored on a new machine.
|
||||
if [[ "${SSR_SNAPSHOT_MACOS_PREFS:-true}" == "true" ]]; then
|
||||
ssr::log "Snapshotting macOS preferences"
|
||||
ssr::macos::prefs_export "$backup_dir"
|
||||
fi
|
||||
|
||||
# Record sync time so `ssr status` can report freshness.
|
||||
state_dir="${SSR_STATE_DIR:-$HOME/.local/state/ssr}"
|
||||
ssr::ensure_dir "$state_dir"
|
||||
|
||||
Reference in New Issue
Block a user