AppleScript Editor "could not be saved"

I’m having major problems with AppleScript Editor on OS X 10.8.4 or 10.8.5 . A script I have successfully been amending and adapting for years has in the last week changed to become unable to be amended and saved.

Pretty sure this is NOT permissions as I can recreate the problem when pasting into a new script file and on several Macs, as a fresh user and even on a Apple support person’s Mac but can’t explain or fix.

I can also recreate when pasting three lines into a new script then repeating them.

It seems related to the content of the script. If you would like to download the sample script from here http://circularsoftware.com/can_save.scpt.zip (obviously been saved) but then just copy and paste ALL the lines again at the end to create a script with double the size (too big to post here) and let me know if that happens for you and if you can explain I’d be most grateful!!

Hope someone can help as I’m really tearing my hair out :frowning:

In which folder are you trying to save it ?

Here, I opened it, added an instruction and saved it with no problem in my Download folder (the one where I got it).

KOENIG Yvan (VALLAURIS, France) vendredi 27 septembre 2013 16:53:57

Hi KOENIG Yvan

Thanks for responding but it doesn’t seem to matter where the file is saved I’m sure it’s NOT a permissions thing.

Try copying ALL the lines and pasting them again as the end of the script and then attempting to save it. The real script of course has many lines of different code but t is how I managed to recreate a simulation of the problem.

Thanks again

HI. Welcome to MacScripter.

The downloaded script is an extreme example of data bloat. All those list values are compiled into it and, after it’s run, the last three are stored in the three top-level variables it sets. (The current values of top-level, or “run handler” variables are, like those of globals and properties, saved back into the script file.) It autosaves OK when I double its length and compile it, but not after I run it.

Without seeing your real script, one can only guess what the problem is. It probably isn’t as extreme as the downloaded one with regard to source code, but it possibly does have some top-level variables with very bulky values. There’s a limit to how much variable data can be saved back into the script, so the variables either need to be reset at the end of each run to something short like “” (which works in the case of the downloaded script), or else they need to be locals.

Thanks Nigel, sounds promising and something to work with at least. Is there a way to somehow clear all variables or to know which ones are the culprits?

Hi again Nigel

Just trying to resolve it this end, can you post the line(s) used to clear the variables that you added to enable it to save?

Hi Dan.

Sorry. I think I spoke too soon with regard to Autosave in AppleScript Editor, which has proved to be a bit of a disaster in several ways. In the immediate term, you could try simply recompiling the script and then waiting for Autosave to have another go. This works for me with the doubled-length downloaded script.

But what I described in my previous post is a known problem with scripts run under normal circumstances. Successful cures have been:

  1. Set the variables which have long values to short values just before the script exits:
set FirstCharCantBeDigit to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
set CCAllowedChars to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "€", "∞", "¢", "≠", "˜", """, "Ï€", "ø", " ", "∑", "Å“", "∂", "Æ’", "-", "Ë™", "∆", "Ëš", "-", ".", "-", "÷", "≥", "≤", "-", "-", "∫", "√", "-", "≈", "Ω", "â„¢", "¹", "º", "fi", "fl", "¡", "'", """, "∏", "°", "ž", "Å’", "", "˘", "Ëœ", "ˆ", "ı", "â—Š", "Ÿ", "ü"}
set CS6AllowedChars to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}

-- De-bulk the variables at the end of the script to reduce the amount of data saved back to the script file.
set FirstCharCantBeDigit to ""
set CCAllowedChars to ""
set CS6AllowedChars to ""
  1. Declare the variables to be used local, so that they’re only temporary and aren’t saved back into the script:
local FirstCharCantBeDigit, CCAllowedChars, CS6AllowedChars

set FirstCharCantBeDigit to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
set CCAllowedChars to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "€", "∞", "¢", "≠", "˜", """, "Ï€", "ø", " ", "∑", "Å“", "∂", "Æ’", "-", "Ë™", "∆", "Ëš", "-", ".", "-", "÷", "≥", "≤", "-", "-", "∫", "√", "-", "≈", "Ω", "â„¢", "¹", "º", "fi", "fl", "¡", "'", """, "∏", "°", "ž", "Å’", "", "˘", "Ëœ", "ˆ", "ı", "â—Š", "Ÿ", "ü"}
set CS6AllowedChars to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
  1. Put the top-level running code inside a handler so that the variables are local by default:
on myMainHandler()
	set FirstCharCantBeDigit to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
	set CCAllowedChars to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "€", "∞", "¢", "≠", "˜", """, "Ï€", "ø", " ", "∑", "Å“", "∂", "Æ’", "-", "Ë™", "∆", "Ëš", "-", ".", "-", "÷", "≥", "≤", "-", "-", "∫", "√", "-", "≈", "Ω", "â„¢", "¹", "º", "fi", "fl", "¡", "'", """, "∏", "°", "ž", "Å’", "", "˘", "Ëœ", "ˆ", "ı", "â—Š", "Ÿ", "ü"}
	set CS6AllowedChars to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
	
	-- Whatever else the script does.
end myMainHandler

myMainHandler()

Thanks for posting that.

Unfortunately all three solutions still come up with the same problem and “could not be saved” :frowning:

I now have an example here http://circularsoftware.com/nigel2.scpt.zip which WILL save but simply by adding a few chars to the last line from

set CS6AllowedChars to {“a”, “b”, “c”, “d”, “e”, “f”, “g”, “h”, “i”, “j”, “k”, “l”, “m”, “n”, “o”, “p”, “q”, “r”, “s”, “t”, “u”, “v”, “w”, “x”, “y”, “z”, “0”, “1”, “2”, “3”, “4”, “5”, “6”}

to

set CS6AllowedChars to {“a”, “b”, “c”, “d”, “e”, “f”, “g”, “h”, “i”, “j”, “k”, “l”, “m”, “n”, “o”, “p”, “q”, “r”, “s”, “t”, “u”, “v”, “w”, “x”, “y”, “z”, “0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”}

will now NOT save

Hello.

This is an extreme shot in the dark, but the zeal is to minimize what your AppleScript is to save when it saves. Normally the entire AppleScript environment is saved with a script.

I believe you can alleviate that by adding a property at the start of your script:

property parent : AppleScript

I hope this helps.

I haven’t pinned down your problem yet, but observations:
(1) osacompile reports a little more specifically: “storage error: Internal table overflow. (-2707)”
(2) This is definitely a language internals issue, as it occurs on my very different system.
(3) I am having trouble finding the error consistently.

Model: PPC G4 Dual-800Mhz
AppleScript: 1.10.7
Browser: Safari 533.19.4
Operating System: Mac OS X (10.4)

This is then one of the cases in which seting the parent property to AppleScript, in the script in question may help. :slight_smile:

But it really only remedies the symptom, and not the cause. I think some restructuring of the data may also help, like for instance putting the data into a script object within the script, (which also should have set the parent property to AppleScript.

This is a very awkward situation, when it happens, I wish the Op good luck!

Is this post from nine years ago still relevant?!
http://macscripter.net/viewtopic.php?id=11760

Basically there is a maximum size for any AppleScript.

“There is some sort of limit to how much code I can have in the script . will report an Internal table overflow (-2707) error when trying to save the script. It compiles OK, however.”

There’s a limit to most things :wink:

The limit in AppleScript is to the number of “objects” in the script, where “objects” encompasses not just variables but also statements, identifiers, you name it. I wouldn’t be surprised if elements in long literal lists are regarded as separate “objects” in this context, and that may be pushing you over the limit.

There are a couple of workarounds you could try. if your script really uses long lists of individual characters, you should be able to rework your code to use a single string, either converting it to a list on the fly, or better still, changing how it is used. You can check if a character is in a string of characters, and its offset if need be, as easily as you can check if it’s in a list of characters, and probably more quickly.

Hello

I tested a given proposal :

I used Find/Replace to convert

local FirstCharCantBeDigit, CCAllowedChars, CS6AllowedChars

set FirstCharCantBeDigit to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
set CCAllowedChars to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "€", "∞", "¢", "≠", "˜", """, "Ï€", "ø", " ", "∑", "Å“", "∂", "Æ’", "-", "Ë™", "∆", "Ëš", "-", ".", "-", "÷", "≥", "≤", "-", "-", "∫", "√", "-", "≈", "Ω", "â„¢", "¹", "º", "fi", "fl", "¡", "'", """, "∏", "°", "ž", "Å’", "", "˘", "Ëœ", "ˆ", "ı", "â—Š", "Ÿ", "ü"}
set CS6AllowedChars to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}

into


local FirstCharCantBeDigit, CCAllowedChars, CS6AllowedChars

set FirstCharCantBeDigit to text items of "0123456789"
set CCAllowedChars to text items of "abcdefghijklmnopqrstuvwxyz0123456789€∞¢â‰ ˜"πø ∑œ∂ƒ-˙∆˚-.-÷≥≤--∫√-≈Ω™¹ºï¬ï¬‚¡'"∏°žÅ’˘˜ˆı◊Ÿü"
set CS6AllowedChars to text items of "abcdefghijklmnopqrstuvwxyz0123456789"

In fact I did the trick on your complete script (plus one trio added to check that it can’t be saved).
The edited version saved flawlessly.
I applied Copy paste so that the set something trio was embedded twice the time it is in your origional script and this time it saves again flawlessly.
With 244 copies of the trio it saves again flawlessly.

It seems that with that we are on the good track.

KOENIG Yvan (VALLAURIS, France) samedi 28 septembre 2013 10:26:08

Hi Yvan.

Those elements should of course be ‘characters of .’ unless AppleScript’s text item delimiters are explicity set to “” or to {“”} first. They shouldn’t be assumed to be at their default setting.

Hello Nigel

Of course you are right. I made the changes too quickly.

KOENIG Yvan (VALLAURIS, France) samedi 28 septembre 2013 11:03:34

One other point: whether the error is triggered or not when saving manually can depend on whether you’re saving as run-only – for run-only scripts the threshold is a bit higher, because without the source there are fewer objects to be saved.

So in theory you could probably copy your script into a .applescript script, where autosaving is not a problem because it will only autosave as text, compile there, and export run-only, with more chance of success.

But I really wouldn’t advise that except in desperate circumstances…

A potential time-waster here is that we’re discussing a demo script which happens to contain several iterations of three list-setting lines. We’ve no idea what’s in the script which actually needs the cure.

However, we seem to be agreed from previous experience that the probable cause of the problem is data bloat and that Dan should be looking at ways to reduce the amount of data which AppleScript (at run time) and AppleScript Editor (during editing) try to store in the script file. The amount of data flying around while the script’s actually running shouldn’t be a problem as long as it’s not being held in persistent variables when the script exits.

Strategies (mostly suggested above) include:

¢ Don’t compile bulky objects as literal values into the script, but use less bulky alternatives, commands, and references to set them up when the script runs.
¢ Alternatively, store them somewhere other than in the script.
¢ Prefer local variables where possible so that their contents aren’t automatically saved to the script file when the script exits.
¢ Replace bulky values with minimal-bulk ones in persistent variables which don’t need to persist ditto.
¢ Don’t replicate data which could be shared or reused.

Hello Nigel

When I use properties, I define them with empty values.
I set their values when entering the script and reset the empty values when leaving the script.

property FirstCharCantBeDigit : {}
property CCAllowedChars : {}
property CS6AllowedChars : {}

set FirstCharCantBeDigit to characters of "0123456789"
set CCAllowedChars to characters of "abcdefghijklmnopqrstuvwxyz0123456789€∞¢â‰ ˜"πø ∑œ∂ƒ-˙∆˚-.-÷≥≤--∫√-≈Ω™¹ºï¬ï¬‚¡'"∏°žÅ’˘˜ˆı◊Ÿü"
set CS6AllowedChars to characters of "abcdefghijklmnopqrstuvwxyz0123456789"

set FirstCharCantBeDigit to {}
set CCAllowedChars to {}
set CS6AllowedChars to {}

In fact I replicated 1 090 times the trio building the lists and was able to save the compiled script which reached 945 653 bytes. Of course it saved too after running because the properties were cleared on exit.
With an extraneous trio I was unable to save.

It seems that I reached the size limit for a compiled script.
Isn’t it a sufficient size ?

KOENIG Yvan (VALLAURIS, France) samedi 28 septembre 2013 18:23:19