Mac OS X has a lot of files that are hidden from view in the Finder. They are hidden for a very good reason, which is most of them are system files that you don’t need to mess with if you want your computer to keep working well. However, there are occasions where it would nice to be able to view these files in the Finder.

This script lets you toggle the view on and off. So, you can turn it on, do what you need and then turn it off.

[codesyntax lang=”applescript”]
try
set toggleView to (do shell script “defaults read com.apple.Finder AppleShowAllFiles”)
on error
set toggleView to “NO”
end try

if toggleView is “NO” or toggleView is “0” then
set br to display dialog “Showing hidden files is disabled.” & return & “Would you like to enable it?” buttons {“Yes”, “No”} default button {“No”}
set theAnswer to the button returned of br
if theAnswer is “Yes” then
do shell script “defaults write com.apple.Finder AppleShowAllFiles YES”
do shell script “killall Finder”
display dialog “Showing hidden files has been enabled” buttons {“Ok”} giving up after 5
end if
else
if toggleView is “YES” or toggleView is “1” then
set br to display dialog “Showing hidden files is enabled.” & return & “Would you like to disable it?” buttons {“Yes”, “No”} default button {“Yes”}
set theAnswer to the button returned of br
if theAnswer is “Yes” then
do shell script “defaults write com.apple.Finder AppleShowAllFiles NO”
do shell script “killall Finder”
display dialog “Showing hidden files has been disabled” buttons {“Ok”} giving up after 5
end if
end if
end if
[/codesyntax]

Copy the code into AppleScript Editor and then save it out as an application. Double clicking on it will bring up a dialog box telling you the current state of viewing hidden files and gives you the option of switching it. Since you have to restart the Finder after you make this change you’ll see the Finder quit and restart.