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!

[code]
on run
set hiddenState to (do shell script "/usr/bin/defaults read com.apple.Finder AppleShowAllFiles")

try
tell application "Finder" to quit

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

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

FinderCheck()
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
[/code]