Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

An Applescript error appending to list objects - I believe this is a bug?

Try this on your machine....

Step 1: Paste this script into your Script Editor and Save it to any file name you want to give it.

Step 2: Run the script and hit Command-S to save the script.
-------

set xLimit to 8144
set aList to {}

repeat with I from 1 to xLimit
set end of aList to I
end repeat

-----------

This should work just fine.

Step 3: Now change the value of 8144 to 8145 and run the script
-- no problem either ... UNTIL you TRY TO SAVE THE FILE.

Control-S, File/Save and File/Save as ...don't work.

Script Editor says "The document xxxx.scpt could not be saved"

I also tried this on a different computer with the same result.

Both machines are up on the latest version of Leopard and I am running
on my Imac which is configured as follows:

Model Name: iMac
Model Identifier: iMac8,1
Processor Name: Intel Core 2 Duo
Processor Speed: 3.06 GHz
Number Of Processors: 1
Total Number Of Cores: 2
L2 Cache: 6 MB
Memory: 4 GB
Bus Speed: 1.07 GHz
Boot ROM Version: IM81.00C1.B00
SMC Version: 1.30f1

Now I also tried this with Script Debugger 4.5.2 (Latest release)
Here the error on saving is more precise:

" Cannot Save Document
Signaled when the runtime stack overflows
(errOSAStackOverflow:-2706)"

The error is in CocoaSpeak but a Stack Overflow is potentially dangerous to
execution stability. I dont feel comfortable with just trying to ignore this.

Page 233 (appendix B) of the Applescript language guide is not more descriptive
than the above.

Anybody else know about this? Am I doing something wrong in trying
to append to an existing list? I've tried other variations before posting
this note. Some of them are:

1) Initializing aList with 1 or 2 elements first -- same result but xLimit
has to be set to 8146 (for 1 element) or 8147 for (2 elements) to fail.

2) Using a reference to aList such as

set refaList to a reference to aList

No luck here either --- Same result.

3) Putting ()'s around aList or using my I or my alist constructs
all yield the same result.

4) Just for completeness I tried the following dreadfully slow technique
inside of the loop.... ah yes, you can go above 8150 but somewhere on or
before 8190 it results the same as all the other ways.

set aList to aList & {I}

Even the sledgehammer failed.

You will not notice this error if you make a change to the script and then save it.

It will only be obvious if you run the script and try saving immediately
afterward -- without making any changes.


Ken Higgins

Imac, Mac OS X (10.5.4), Windows 2000 Advanced Server with Domain and Private DNS DHCP servers

Posted on Feb 6, 2009 7:09 PM

Reply
Question marked as Best reply

Posted on Feb 6, 2009 7:36 PM

I believe this is a known issue that involves the size/number of items saved in the script file (properties and globals are saved with the script). This goes away if you set the list to {} after you are done with it or put your statements in a handler (to make the list local).
2 replies

Feb 6, 2009 8:03 PM in response to red_menace

Hi Red...

Good call.

I tried this script. When I commented out "bb" it showed the error as
as I indicated. However, when I UNCOMMENTED the bb line, as suggested, it worked.

I also tried this inline (outside of a handler) and replicated the same result.
So the idea is -- we have to make sure that we close out these
lists prior to terminating the script. That's not great but its a valid workaround.

thanks so much.
Ken Higgins


---
set bb to myHandler()
set bb to {} <------

on myHandler()
local aList

set xLimit to 9000
set aList to {}

repeat with I from 1 to xLimit
set end of aList to I
end repeat
return aList
end myHandler

An Applescript error appending to list objects - I believe this is a bug?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.