To augment Bruce’s reply, properties and their current values are saved back to the script file after each run of the script (except when the script’s run in Script Editor). Not only properties, in fact, but also globals and what are know as “top level variables”. Top level variables are those that are used at the “top level” of the script ” ie. in the (implicit or explicit) run handler.
If the above is your entire script, it’s all within an implicit run handler, so dialogString, textBlob, and n are all top level variables. The value of textBlob at the end of the run is the whole of the text of the TextEdit document. This is saved back to the script file, so it’s the likely cause of your bloat.
The values of local variables are not saved back to the file, so you could explicitly declare the variables as local:
local dialogString, textBlob, n
tell application "TextEdit"
set dialogString to ""
set textBlob to ""
repeat with n from 1 to (count of documents)
set textBlob to text of document n
set dialogString to ((dialogString & (name of window n) as string) & ": " & (count of textBlob) as string) & return
end repeat
display dialog dialogString
end tell
I personally find it more convenient to put the “top level” action into an ordinary handler, where variables are local anyway unless declared otherwise. The handler call is then the only thing in the implicit run handler. (I use the name main() by analogy with the C programming language, but it has no significance in AppleScript):
on main()
tell application "TextEdit"
set dialogString to ""
set textBlob to ""
repeat with n from 1 to (count of documents)
set textBlob to text of document n
set dialogString to ((dialogString & (name of window n) as string) & ": " & (count of textBlob) as string) & return
end repeat
display dialog dialogString
end tell
end main
main()
If you find you have to use a property or a global to hold a value that’s likely to be very long, a third trick (assuming you don’t need the value next time the script’s run) is to set the affected variable(s) to something very short immediately before the script’s exit point:
-- Blah blah blah
set myBloatedTopLevel to ""
set myBloatedGlobal to ""
set myBloatedProperty to ""
-- End of script.