I came to understand that the following is the way to toggle the visibility of hidden files:
defaults write com.apple.finder AppleShowAllFiles YES
# replace YES with NO to hide hidden files
killall -HUP Finder /System/Library/CoreServices/Finder.app
Is there a way to show/hide hidden files without killing the Finder?
Best Answer
Edit: This no longer appears to work since El Capitan.
killall Finder
seems to be the only way now.This is my current El Capitan method, which should also work for Mountain Lion & older
For Mavericks & Yosemite…
You don't need to restart the Finder, only refresh the windows.
This Applescript will toggle the state & refresh...
Credit to ganbustein for the improved hide/show routine