I have spent hours this afternoon restarting various startup disks trying to find a cause and fix to this problem. I finally decided to rewrite my Abracapocus application without the idle and quit handlers.
The script, below, does exactly what it's supposed to do without any problems.
There seems to be a problem of some sort with Stay Open applications in Lion. (See my other post "Idle Bug in Lion ASE".) I have no idea what the connection is or why it should cause problems. Stay alert.
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 adds 'AppleShowAllFiles' to the preference file "com.apple.finder.plist"
end try
end try
delay 1
end tell
tell application "Finder" to activate
end toggleInvisibles -----------------------------