We’ve shown you how to reveal hidden files in the Finder from Terminal’s command-line. But if you work with such files a lot, it can be a hassle to open up a Terminal window every time. MacOSXHints reader colmiak came up with an easier way to toggle hidden files from within the Finder, using Automator, a series of shell scripts, and OS X’s Services menu. Commenters on his hint then suggested some improvements (among others: using AppleScript instead of shell scripting); the amended tip works as follows:
Launch Automator and choose Service as your template. Drag the Run AppleScript action from the Utilities library to the work area on the right. At the top right, select Finder.app from the second drop-down box, then No Input from the Service Receives drop-down.
Copy the following code and paste it into the Run AppleScript box (between the lines beginning
on run and
if (do shell script "defaults read com.apple.finder AppleShowAllFiles") is equal to "0" then do shell script "defaults write com.apple.finder AppleShowAllFiles 1"else do shell script "defaults write com.apple.finder AppleShowAllFiles 0"end iftell application "Finder" to quittell application "Finder" to activate
(As you copy and paste, make sure the apostrophes and quotes come through as plain text.) Save the Service (as Toggle Hidden Files or whatever you like) and exit Automator.
You can now turn the hidden files setting on and off by selecting Finder -> Services -> Toggle Hidden Files. If you prefer, you could instead open AppleScript Editor, copy and paste the code above, and save it as an application, which you could launch from the Dock or the desktop. That would also work in pre-10.6 versions of OS X; you could also use this older method in Leopard and Tiger.