applescript to hide/reveal hidden files

There are certain things I find I do now and again which would be nice to automate. One of them is revealing hidden files, on a mac that means the file name begins with a period, like a .htaccess file. Typically I would go into terminal, write a little shell command and then I'd have a messy desktop and file browsing until I got around to hiding hidden files again. So I wrote the below shell script which will do this switch for me. I've even set it up as a trigger in Quicksilver so I can toggle it on and off with a keyboard shortcut. Pretty simple!

on run
set hiddenState to (do shell script "/usr/bin/defaults read AppleShowAllFiles")

tell application "Finder" to quit

if (hiddenState is "ON") then
do shell script "defaults write AppleShowAllFiles OFF"
delay 3
else if (hiddenState is "OFF") then
do shell script "defaults write AppleShowAllFiles ON"
delay 3
end if

on error myError
display dialog "problem:" & myError
end try

end run

on FinderCheck()
tell application "System Events"
if (name of every process) does not contain "Finder" then
tell application "Finder" to launch
end if
end tell
end FinderCheck