Script has grown too large for editors

I started a thread over on Apple Discussions about this problem, but nobody there has been able to help me as of yet .

I have a really large script that I’ve been working on for quite some time: 7899 lines, over 192k characters. Unfortunately, it seems that I can’t make it any bigger. There is some sort of limit to how much code I can have in the script-- any more, and Smile (my editor of choice, although Script Editor 2 will do this as well) will report an Internal table overflow (-2707) error when trying to save the script. It compiles OK, however. Furthermore, to even get this script to compile in the first place it is necessary to tweak the AppleScript formatting from the Formatting pane in Script Editor so that all styles except for “New text (uncompiled)” are formatted the same. (The reason for this is that otherwise the script would have more than 32765 style changes-- not allowed.)

I can’t find any documentation on this error or cases like mine, but I don’t think that it’s my code. The script works fine, but if I copy over one of my larger handlers and rename it-- which doesn’t add any complexity except one more handler-- it will go over this limit and break. Comments do not seem to be included in this limit.

Splitting it up isn’t an option: Most of the handlers need to have read-write access to a set of global properties, in addition to calling other handlers. I tried using load script and the parent property to create a working inheritance model, but it seemed broken (see this other thread at Apple discussions).

I relayed my concerns to the developer of Smile (Emmanuel). He gave me the fix for the styles problem (see above), but he couldn’t figure out what was causing the -2707 error. He reported that he’d seen scripts larger than mine run in Smile.

Yes, I have heard all the wonderful things Script Debugger can do-- I downloaded the demo but was unable to determine that it worked because I couldn’t save. Besides, I’m not ready to plunk down that much money on an editor. Maybe AppleScript Studio can make it work, but somehow I doubt it.

The script is too big to post here, although I’ll email it when asked. If anyone has any insight… This board is probably my last hope for future development of my script.

System: 10.3.2, current on updates as of today. Smile 2.5.9, Script Editor 2.0. B & W G3, 320 MB of RAM total.

I’ll bite–let me take a look at the script. Is it possible for you to upload the script someplace instead of emailing it?


Just tried and you are true. I was unable to save 250 Kb. This must be a new “feature” of AS, because in previous versions we were able to compile and save even MB! (I tested both jaguar and panther, same results in all compilers)

For anyone interested, a version of this script that will produce error is located at:

And a functioning version is located at:

The only difference between the two scripts is that BotScriptOverflow.txt contains an additional handler (doPlanetSaver3()) that is just the code of doPlanetSaver2() renamed.

The script will expect you to locate an application program called TWScripter. This can be obtained from

Can you actually upload the script someplace, not just an HTML page of the script contents? There seem to be high-ASCII characters that aren’t making it through. From first glance, however, there is a lot of room for streamlining your code:

  • every “number of characters of x” can be simplified to “count x”

  • your simple if statements can be shortened from “if x = 1 then
    set x to 2
    end if” to “if x =1 then set x to 1”

  • you can eliminate the extraneous use of the word “the” (e.g., “set the end of x to y” can just be “set end of x to y”)

  • “is” can be “=” (e.g., “if x is y” can be “if x = y” or “x is not y” can be “x ? y” – the “?” is actually the not equal sign which you can enter by typing option-=)

  • your dialogs can be simplified from “buttons “Cancel” default button “Cancel” with icon stop” to “buttons “Cancel” default button 1 with icon 0”. Further, you could write a simple handler for displaying a dialog instead of writing “display dialog” every time.

  • you can simplify your variable casting from multiline to a single line:
    set x to 1
    set y to 2
    set z to 3

can be set {x, y, x} to {1, 2, 3}

  • you can use a numeric index instead of the words “last” or “first” (e.g., “last word of x” becomes “word -1 of x”)

I’m sure there are plenty of other ways to streamline this, especially use a few more very basic subroutines (such as the one I mentioned above for displaying dialogs).

Good luck.


Thanks John, will do. is the new release of the compiled script. I have optimized the dialogs somewhat (testing still pending, however).

Um, that didn’t work for me. When I downloaded the file and opened it in Script Editor, it was blank. I think you need to encode the script file using something like StuffIt.


MacOS X AppleScripts, which use the data fork, should be internet-safe. Nonetheless, here is a .dmg I made up:

It seems that my script causes Script Editor to freeze on open-- it’s bigger than Script Editor can effectively edit. You’ll need a more capable editor like Smile. I have confirmed that the script will survive HTTP transport in its .dmg and will open in Smile. (Script Debugger should be able to handle it as well if it’s as good as they claim)(XCode might also be able to open it). Be sure to follow the Formatting fixed outlined in my first message-- otherwise you may experience Out of Memory errors during compiling.

[color=violet]* I edited the URL to match the real “.dmg”


For those of you who have downloaded my scripts, what is your opinion of them? There is certainly room for optimization, but that would only free up so much space. Is this an AppleScript bug? If so, how do I go about reporting it to Apple?

My efforts at splitting this script up are going nowhere, probably due to the bizarre structure of TWScripter scripts.

I didn’t really studied your code, but most probably someone able to write such amount of code is also able to optimize it… So, it must be a good-coded one.

Here is a page to submit bug reports:

And, most probably, the fast way is posting a message at Apple’s AppleScript-Users List, where C. Nebel or C. Espinosa can read it directly.