Puzzle: defaults commands not changing settings in TotalFinder

I am writing a post-installation script to set up the various TF configurations for our company. I am attempting to run “defaults write” commands to set up about 30+ configurations for existing users and to the User Template to configure new users as well; however, for some reason, in my tests, even though the script works successfully, the TF settings are not being changed. I would appreciate a sanity check.

My workflow: After the package copies the TotalFinder package to /private/tmp, the package’s post-installation script uses a helper function to run the defaults commands against a defined path that can vary, depending if I am applying the commands against existing users or the User Template. The variable for this path is $defaultsPATH. The basic steps of the script:

  1. Use “installer” command to install the package to hard drive
  2. In User Templates, check if com.apple.finder.plist exists. If not, use defaults command to create file.
  3. Run defaults commands against defaultsPATH="/System/Library/User Template/English.lproj/Library/Preferences/com.apple.finder"
  4. Checking against existing users, the commands are run against defaultsPATH="/Users/$user/Library/Preferences/com.apple.finder"(where $user is an existing user)

For the helper function that runs the defaults commands to configure TF, a sample command is like this:

echo "TotalFinderShowStatusItem -bool NO..."
	/usr/bin/defaults write "$defaultsPATH" TotalFinderShowStatusItem -bool NO
		TotalFinderShowStatusItem=`/usr/bin/defaults read "$defaultsPATH" TotalFinderShowStatusItem`
		echo "Verifying configuration..."
		if [ "$TotalFinderShowStatusItem" = "0" ]; then
				echo "SUCCESS: Configuration passed."
				echo "WARNING: There was a problem with the configuration.  Exit Code: $?"

The script runs fine and verifies each configuration as correct, but the settings are not changed. I am figuring I am missing something really simple here, but I am not catching it.

I appreciate any help in advance.

Ok, nevermind. I am a dunce.

defaultsPATH="/Users/$user/Library/Preferences/com.apple.finder"(where $user is an existing user), as written, creates a Library folder at /Users. I corrected it and it applies correctly.

I’m glad you have resolved it.

If I understand it correctly you run the defaults command before TotalFinder is injected into Finder. Changing TotalFinder plist keys at that point is good and safe.

I just wanted to point out that there could be some issues changing defaults while Finder/TotalFinder is running. Plist defaults are cached in memory and TotalFinder/Finder could overwrite the file on disk with values which got changed within the app. This is unlikely, but could happen if user touches preferences or internal state of defaults changes for any reason.

A safe way is to make sure Finder is not running when changing plist. It can be done this way:

osascript -e "tell application \"Finder\" to quit
... do your defaults tweaks here
osascript -e "tell application \"Finder\" to «event BATFinit»"