Answer
Command Line Method:
To show hidden files in finder in Mac OS X 10.4:
defaults write com.apple.finder AppleShowAllFiles -bool true
To hide hidden files in finder in Mac OS X 10.4:
defaults write com.apple.finder AppleShowAllFiles -bool false
AppleScript Method:
Here's my version:
set onOff to do shell script "defaults read com.apple.finder AppleShowAllFiles"
if onOff = "NO" or onOff = "OFF" then
set newState to "show"
set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles ON"
else
set newState to "hide"
set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles OFF"
end if
display dialog "Are you sure you want to " & newState & " hidden files? (This will restart the Finder)" buttons {"Cancel", "OK"} default button 2
copy the result as list to {BUTTONPRESSED.EN_US}
if the buttonPressed is "OK" then
try
tell application "Finder" to quit
do shell script OnOffCommand
delay 1
tell application "Finder" to launch
end try
end if
In Mac OS X, there are three different ways a file or directory can be made invisible in the finder: it can have the "invisible" attribute set (as in older Mac OS systems), its name can start with "." (as in other unix systems), or its name can be listed in the /.hidden file. Many of the files and directories listed above are actually invisible for multiple reasons (e.g. /bin is listed in /.hidden, as well as having its invisible attribute set).
Note that OS X only respects the .hidden file on its boot volume, so if you boot from another disk, several normally-hidden files will suddenly be visible. Also, since Mac OS 9 (and older versions) only recognize the invisible flag, even more of these files (mainly /.vol, /mach, /mach.sym, and sometimes .DS_Store) will be visible when you boot into Mac OS 9.