I created a Service with Automator on a Mac running "Lion 10.7.3". The Service toggles via a shell script the visibility of hidden files in the Finder and works like a charm. Here's the script:
STATUS=`defaults read com.apple.finder AppleShowAllFiles`
if [ $STATUS == YES ];
then
defaults write com.apple.finder AppleShowAllFiles NO
else
defaults write com.apple.finder AppleShowAllFiles YES
fi
killall Finder
Because this script was doing so nice, I thought I could do a similar script that toggles the key closeViewZoomFollowsFocus between the values TRUE and FALSE. So I did another script:
STATUS=`defaults read com.apple.universalaccess closeViewZoomFollowsFocus`
if [ $STATUS == TRUE ];
then
defaults write com.apple.universalaccess closeViewZoomFollowsFocus FALSE
else
defaults write com.apple.universalaccess closeViewZoomFollowsFocus TRUE
fi
The problem with this script is that the change takes no effect. To be precise: The script changes the value as it should, I checked it in the Terminal with defaults read com.apple.universalaccess closeViewZoomFollowsFocus. But the change is not activated.
In my original script that toggles the hidden files I solved this with killal Finder. Unfortunately I have no idea how to achieve an instant activation of the changed default in my second script.
When you change the same default via the System Preferences, it does take effect instantly without logoff/logon or anything else. So I wonder about a command that activates such a change instantly in the background. Any ideas?