Trying to complete it...

Hi all,

I have been searching for a forum to help me with my AppleScript as I am totally stumped. I have been writing this script now for about 2 months and have almost completed it until I hit one last error.

The script is doing the follow.

· Getting various information from the user
· Copying a template folder (with sub-folders) to a user specified location.
· Then renaming the folder names according to the user information

I have excerpted the final section of the script when whenever i execute gives the the error code Finder is out of memory.
I have tried making an application of the script and increasing its memory to 50000meg and it still gives me the same error :cry:

Here is the code. I am getting the entire contents of the user specified folder and making them into a string. When I try to rename them I get that error.

tell application “Finder”
activate
set fileList to entire contents of folder “000-AAA_[Title23CharsMax] copy” of disk “Odette’s Files” as list
set name of folder item 1 of list fileList to “success”
display dialog “Success!!!”
end tell

nb: Item 1 returns 243 items.

I need to make it so I can rename folders whenever the user specifies a location, which is put into the variable ‘destination_folder’ however I keep getting this error. If anyone knows of a more efficient way either I would also appreciate the feedback.

If ANYONE can help me with this piece of script, or the entire script, I would be eternally grateful. The script is not terribly difficult I just feel that there is something simple I am missing…

I have included the total script at the bottom. It looks daunting but it is really very simple. I am not too proficient in AppleScript yet.

Thanks all,

Dave.

implex@optushome.com.au

property masterFile : {alias "Odette's Files:000-AAA_[Title23CharsMax]:"}
repeat
	try
		set dialogResultJob to (display dialog "What is the job No of the new project?¬
	###-AAA_Name
                     Max length                    " default answer "123 - AAA_Name" with icon 1)
		set theTextjob to text returned of dialogResultJob --coercion job to text
		set theButtonjob to button returned of dialogResultJob --this is required even though we only need text above
		
	on error errMessage number errNum
		if errNum = -128 then
			display dialog "The user hit cancel!" buttons {"Exit"} default button 1
			if button returned of result = "Exit" then
				error number -128
			end if
		else
			display dialog "An error occurred: " & errMessage
		end if
	end try
	
	if the (count of theTextjob) < 32 then
		exit repeat
	end if
end repeat

try
	set dialogResultAuthor to (display dialog "What is the Author and edition?¬
Author -1Ed
                     Max length                    " default answer "Author -1Ed" with icon 1)
	set theTextAuthor to text returned of dialogResultAuthor --coercion Author Name to text
	set theButtonAuthor to button returned of dialogResultAuthor --this is required even though we only need text above
	
on error errMessage number errNum
	if errNum = -128 then
		display dialog "The user hit cancel!" buttons {"Exit"} default button 1
		if button returned of result = "Exit" then
			error number -128
		end if
	else
		display dialog "An error occurred: " & errMessage
	end if
end try

try
	set dialogResultBookTitle to (display dialog "What is the Book title and edition?¬
Book title-1Ed¬
                     Max length                    " default answer "Book title-1Ed" with icon 1)
	set theTextBookTitle to text returned of dialogResultBookTitle --coercion Book Title to text
	set theButtonBookTitle to button returned of dialogResultBookTitle --this is required even though we only need text above
on error errMessage number errNum
	if errNum = -128 then
		display dialog "The user hit cancel!" buttons {"Exit"} default button 1
		if button returned of result = "Exit" then
			error number -128
		end if
	else
		display dialog "An error occurred: " & errMessage
	end if
end try


repeat
	try
		set dialogResultISBN to (display dialog "What is the ISBN ? 
10 digits with no spaces or dashes
     Max    
" default answer "01701*****" with icon 1)
	on error errMessage number errNum
		if errNum = -128 then
			display dialog "The user hit cancel!" buttons {"Exit"} default button 1
			if button returned of result = "Exit" then
				error number -128
			end if
		else
			display dialog "An error occurred: " & errMessage
		end if
	end try
	
	set theTextISBN to text returned of dialogResultISBN --coercion ISBN to text
	if the theTextISBN != "01701*****" and (count theTextISBN) = 10 then
		exit repeat
	end if
end repeat

set theISBN to "ISBN" & theTextISBN --coercion ISBN to text
set theButtonjob to button returned of dialogResultISBN --this is required even though we only need text above


display dialog (theTextjob & " " & theTextAuthor & " " & theTextBookTitle & " " & theISBN)

tell application "Finder"
	activate
	set destination_folder to choose folder with prompt "Where do you want to save the new job?…" --the new location for the object
	(*if the free space of the disk of the destination_folder is less than the size of the masterFile then
		error "Not enough free space to perform the action."
	end if*)
	set filespec to duplicate every item of masterFile to the destination_folder with replacing
	filespec as string
	set fileList to entire contents of folder "000-AAA_[Title23CharsMax] copy" of destination_folder as list
	open destination_folder
	set name of folder item 1 of list fileList to "success"
	display dialog "Success!!!"
	
end tell
beep 2

Because it’s the Finder that’s out of memory, not the script.

I don’t know if they will solve the problem but here are a couple of things that I would change. Your variable fileList is already a list, so line 3 shouldn’t need ‘as list’ on the end. In line 4, I don’t think it’s necessary to say ‘of list fileList’.

tell application "Finder"
    activate
    set fileList to entire contents of folder "000-AAA_[Title23CharsMax] copy" of disk "Odette's Files"
    set name of folder item 1 of fileList to "success"
    display dialog "Success!!!"
end tell

Are you sure that every item returned by ‘entire contents’ will be a folder?

Hi,

Thanks for the reply. I’ll test that script as soon as I get home. Also not every thing that is returned from

will not be a folder. There are a few various other things in there including folders that do not need to be renamed.

Dave

“entire contents of folder… as list” should return (in a folder containing two files) a list of 1 item (this item is a list of two items):

{
   {file 1...,
     file 2...
   }
}

So, item 1 of this list is:

{file 1...,
  file2...
}

If this is true, then

set name of folder item 1 of list fileList to "success"

would attempt to set name of a folder to a 243-items-list…

Perhaps this is because “finder is out of memory”, when trying to coerce a 243-items-list to a string… (I don’t know, sorry, working on OS X).

Perhaps you could try request to the Finder an alias list, and work with aliases, instead “file specs”:

set x to entire contents of this_folder as alias list
set name of x's item 1 to "hello, dolly"

“as alias list” returns (as expected) a list of aliases:

{alias "HD:Desktop Folder:File 1",
  alias "HD:Desktop Folder:Folder 1"
}

And you can change a file/folder name easily providing the Finder an alias…
:rolleyes: