I'm writing a utility that configures some UserDefaults values for me, such as for initializing new Macs to my personal tastes.
It reads a set of configurations from an input file. It then applies the specified preferences to various applications using the CFPreferencesSetValue API. I use it instead of NSUserDefaults, because the latter doesn't let you write to NSGlobalDomain (/Library/Preferences/.GlobalPreferences.plist).
It works well, but here's a twist: I want to be able to detect which applications have had their preferences' values actually change, and which ones already have the desired preferences in place. This allows me to automatically restart "dirty" applications such as Finder, Dock, etc. only if necessary.
I achieve that by doing this:
Is there a way to safely make this change, without a risk of last-write-wins clobbering other changes?
It reads a set of configurations from an input file. It then applies the specified preferences to various applications using the CFPreferencesSetValue API. I use it instead of NSUserDefaults, because the latter doesn't let you write to NSGlobalDomain (/Library/Preferences/.GlobalPreferences.plist).
It works well, but here's a twist: I want to be able to detect which applications have had their preferences' values actually change, and which ones already have the desired preferences in place. This allows me to automatically restart "dirty" applications such as Finder, Dock, etc. only if necessary.
I achieve that by doing this:
Reading the existing preferences' values
Comparing the just-read values from the desired values as read from the config file
Noting down which domains have values need changing
Applying the preferences changes
Restarting the apps corresponding to the dirty domains.
Is there a way to safely make this change, without a risk of last-write-wins clobbering other changes?