Wednesday, June 26, 2019

#1 2018-12-10 06:49:43 pm

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 86

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.

Thanks.

Last edited by peavine (2018-12-10 07:26:21 pm)

Offline

 

#2 2018-12-11 05:34:17 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4884

Re: Applescript File Size

Hi.

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.


NG

Offline

 

#3 2018-12-11 09:26:24 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 86

Re: Applescript File Size

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.

Last edited by peavine (2018-12-20 10:15:35 am)

Offline

 

#4 2018-12-11 04:01:02 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5708

Re: Applescript File Size

Nigel Garvey wrote:

The "versions" system does tend to make script files grow



It shouldn't -- it just saves copies elsewhere.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#5 2019-05-03 08:14:01 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 86

Re: Applescript File Size

Nigel Garvey wrote:

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.



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

Applescript:

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.

Last edited by peavine (2019-05-03 12:51:14 pm)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)