markforster
Toggle Hidden Files in Finder using AppleScript

Tested on Leopard 10.5.6, I totally ripped these solutions from various sources on the net after about 5 minutes of googling.

The solutions below arent great but until I can be bothered to conjure my own more elegant implementation or have time to google further, both are enough for a mac novice to quickly view hidden files/folders without resorting to yet another app to plug a missing feature in OSX.

Solution 1 - The AppleScript Way

Navigate to ‘/System/Library/CoreServices/Menu Extras’ and double tap ‘Script Menu.menu’. This should add a script icon to your menu bar.

Grab the following apple script…

tell application “Finder”
activate
set previous to “FALSE”
set previous to do shell script “defaults read com.apple.finder AppleShowAllFiles”
display dialog “Show Hidden Files… ” & previous buttons {“TURN ON”, “TURN OFF”} default button 2
copy the result as list to {buttonpressed}

if previous is “TRUE” and the buttonpressed is “TURN OFF” then
do shell script “defaults write com.apple.finder AppleShowAllFiles FALSE”
quit
end if
if previous is “FALSE” and the buttonpressed is “TURN ON” then
do shell script “defaults write com.apple.finder AppleShowAllFiles TRUE”
quit
end if
end tell

delay 1
tell application “Finder” to launch

… and save this as “ToggleHiddenFiles.scpt” inside /Users/your-user-name/Library/Scripts folder. The folder may not exist so you will have to create it if it doesn’t.

Solution 2 - The Terminal Way

To view hidden files and folders open terminal and throw the following at it:

$ defaults write com.apple.finder AppleShowAllFiles TRUE

$ killall Finder

…and to hide them again…

$ defaults write com.apple.finder AppleShowAllFiles FALSE

$ killall Finder