out of memory error

Hi.Probably a really basic q, but I’m a bit of a newbie. I’m getting an out of memory error when running the script below. I use it to process large numbers of files, 1000’s often.

tell application “Finder”
activate
set the chosen_folder to (choose folder with prompt “Pick the folder containing the files :”)
set the audiolistw to (every file of the entire contents of the chosen_folder)

repeat with i from 1 to the number of items in audiolistw
	set this_item to item i of audiolistw
	set the creator type of this_item to "ReCy"
end repeat

end tell

Could I make applescript generate a text file and use this as a list instead of the way it’s doing it now? I have increased it’s memory allocation to no avail. I found no reference to it in the archives.

Thanks in advance for any help, Nick.

You can try (a bit slower, but memory-safe) this UNTESTED code:

set the chosen_folder to (choose folder with prompt "Pick the folder containing the files :")

tell application "Finder"
	repeat with i from 1 to 50000
		try
			set creator type of file i of chosen_folder to "ReCy"
		on error
			exit repeat
		end try
	end repeat
end tell

great thanks for that!

Nick.

This was a common problem when scripting “classic” versions of the Finder. When you set your ‘audiolistw’ variable to ‘every file of the entire contents of the chosen_folder’, the Finder tries to load a list containing a reference to every single one of the files into the variable — and the script hits the memory problem.

Since you want to set the same property of all these files to the same thing, you don’t actually need to ‘get’ the files into the script. Instead, you can use the Finder reference to tell the Finder to get on with it and spare you the details, as it were. I think the following should work for you and will probably be a lot faster than using a repeat loop in the script:

tell application "Finder"
  activate
  set the chosen_folder to (choose folder with prompt "Pick the folder containing the files :")
  set the creator type of every file of the entire contents of the chosen_folder to "ReCy"
end tell