The original Abracapocus used idle and quit handlers. I removed these. I just submitted Bug # 9831083 with the following test script ...
on run
display dialog "Set invisibles to …" buttons {"Cancel", "Show", "Hide"} default button 3
button returned of the result
if the result = "Show" then
my toggleInvisibles(true)
else if the result = "Hide" then
my toggleInvisibles(false)
end if
end run -----------------------------------------
on toggleInvisibles(show)
tell application "Finder"
(path to preferences folder from user domain) as text
set filePath to the result & "com.apple.finder.plist"
quit
end tell
tell application "System Events"
repeat -- until not (exists application process "Finder")
delay 0.1
if not (exists application process "Finder") then exit repeat
end repeat
delay 1
try
set value of property list item "AppleShowAllFiles" of property list file filePath to show
-- this line fails if the "AppleShowAllFiles" key is not present in a new prefs file.
on error
-- causing this to run.
try
value of property list file filePath
the result & {|AppleShowAllFiles|:show}
set value of property list file filePath to the result
-- this successfully adds 'AppleShowAllFiles' to
-- the preference file "com.apple.finder.plist"
-- and Finder immediately becomes inoperative.
end try
end try
delay 1
end tell
tell application "Finder" to activate
end toggleInvisibles -----------------------------
On a new Lion installation, it kills the Finder, first time, every time.
I will let Apple figure out why.