Update: If you’re running macOS Sierra, ignore the rest of this tip because it’s irrelevant! I had no idea Shift-Command-Period would show/hide hidden files directly in Finder in macOS Sierra. Thanks to NaOH for the great tip via the comments!
Basically, if you want to show invisible files in Finder in Sierra, pressing ⇧⌘-Period will toggle them between hidden and visible. Nice! If you’re on an earlier version of macOS/OS X, however, you may find the macro version useful for easily showing and hiding hidden files in Finder.
This remains here as a reminder of The Hard Way of doing this…
A long-standing—since March of 2001—Mac OS X Hints tip reveals how to display hidden files and folders in Finder. Despite its age, this tip still works in macOS Sierra. Now, normally I don’t want to see all the invisible Unix files in Finder, but there are times (like when I’m working on a web site that might have an .htaccess file) that I want to see them. All it takes to see them is one command and a Finder restart in Terminal:
$ defaults write com.apple.Finder AppleShowAllFiles YES
$ killall Finder
To hide them again, you can either set the pref to NO, or just delete it (defaults delete com.apple.finder AppleShowAllFiles) and then restart Finder again.
I wanted to make this toggling simpler, so I wrote a Keyboard Maestro macro to check the current state and reverse it.
Here’s how the macro looks—as always, you can download it for your own use/modification.
The key to this script is actually in the hidden second step (sorry!) in the above image: The “Excecute Shell Script” command is this one:
defaults read com.apple.finder AppleShowAllFiles
That command reads the current value of the hidden pref—it’ll either be YES or it won’t exist—and saves it to a variable. Once saved in the variable, an “If” loop checks the saved value and either sets or deletes the “show invisible” flag. The AppleScript at the end relaunches the Finder in a slightly nicer way than does just killing it in Terminal.
This works quite well for me; I can see the hidden files when I want them, and hide them again, all with the same command. (Right now, I have it running in Finder only, and via the Keyboard Maestro menu bar icon so I don’t need to remember a keyboard shortcut.)