Unlike Windows, Mac OS X doesn’t offer a GUI-based option to show or hide hidden files and folders in Finder. Hence, you need to manually input the commands via Terminal to do this task which isn’t convenient for most users. To make it easier, you can simply make an executable script to perform the necessary commands and easily toggle between the show/hide files option on your Mac.
For those unaware, you can make any file or folder hidden in OS X by renaming it and placing a period (.) in front of its name. This will make that file/folder invisible in the Finder.
Creating a Shortcut to Show/Hide Invisible Files on Mac OS X –
Search for “AppleScript Editor” from the top right corner of the screen and open the app. Copy the script below and paste it into the editor as shown.
display dialog “Show all files” buttons {“TRUE”, “FALSE”}
set result to button returned of result
if result is equal to “TRUE” then
do shell script “defaults write com.apple.finder AppleShowAllFiles -boolean true”
else
do shell script “defaults delete com.apple.finder AppleShowAllFiles”
end if
do shell script “killall Finder”
Then click on the ‘Compile’ button, choose File > Save As and give it a name. Make sure to select ‘Application’ as the file format and Save.
Run the shortcut and it will ask to ‘Show all files’. Click True to show hidden files and False to hide the hidden files with just a click right from your desktop.
Source: Stack Overflow