Applescript File Size

I’ve noticed that scripts saved in script file format become progressively larger after multiple saves. The size increase is often many times what would be expected by the edits alone.

I thought this might be a result of previous versions of the script that are accessible through the “Revert to” command but I deleted all prior versions of the script and that did not reduce the size of the script.

I was successful in reducing a script’s file size by saving it in text file format and then immediately in script file format. By way of example, I had a 1-line script which had a file size of 112KB and had a file size of 1KB after text-then-script files saves.

Anyone know why this is happening.



The “versions” system does tend to make script files grow while you’re editing them, even if you don’t actively save the changes. It’s both annoying and a life saver. Mostly annoying.

Another thing is that if you run a script before saving it, the values of any persistent variables (properties, globals, or variables used in the run handler and not declared local) will be saved with it. If these values are long lists, they can add to the size fo the file. It can help to recompile scripts immediately before saving them. But I do that anyway and still the file sizes increase disproportionately, so presumably versions are the main culprit.

Thanks Nigel for the response. I had thought perhaps I was doing something incorrectly and its good to know that’s not the case. I will recompile my scripts before saving them to see if that helps.

EDIT (12/20/18):
FWIW, I’ve found that using the “File > Save As” command while retaining the existing file name and Script file format will often significantly reduce file size. For example, a script I use for testing purposes was reduced from 132KB to 4KB.

It shouldn’t – it just saves copies elsewhere.

I found a circumstance where this can happen to a surprising extent. I created an application script that contained the following:

set testFolder to choose folder
tell application "Finder" to set fileList to (files of entire contents of testFolder) as alias list

I ran the script from within the Finder and selected a test folder that contained 3GB of data, which caused the script file size to increase from 101KB to 3.9MB. Recompiling the script or running it on a folder with only a few files reduced the script file size to or near 101KB. Declaring the fileList variable as local or including the tell-application command in a handler (other than the run handler) entirely eliminated any increase in file size.

As part of this, I ran some timing test and saw no difference in the time it took for the script to complete if it was allowed to save the value of the fileList variable.