"Wait until finished before moving" not working pr

This script should work, but when the added items are finished copying, the items added are not moved like they should. The first item added is moved ok, but when more items are added they remains in the source folder untill another item is added to the folder.

I would like to try with the isDone() script but I don´t know where to get it since the code exchange is down. Could someone please email it to me?

Thanks

on adding folder items to this_folder after receiving added_items
–do for every added item

repeat with this_item in added_items
	try
		--process added items one after another 
		ProcessItem(this_folder, this_item)
	end try
end repeat

end adding folder items to

–subroutine that processes items that were added to a folder
on ProcessItem(this_folder, this_item)

--check if file is growing using UNIX "ls" command 
set LastFileSize to -1
set isGrowing to true
repeat until isGrowing is false
	set CurrentFileSize to do shell script ("/bin/ls -l " & (quoted form of (POSIX path of (this_item))) & " | /usr/bin/awk '{print $5}'")
	if CurrentFileSize is equal to LastFileSize then
		set isGrowing to false
	else
		set LastFileSize to CurrentFileSize
		delay 2
	end if
end repeat

--check if file is busy using UNIX "lsof" command 
set isbusy to 1
repeat until isbusy is 0
	set isbusy to ((do shell script ("echo `lsof " & (quoted form of (POSIX path of (this_item))) & " | wc -l`")) as integer)
	if isbusy is not equal to 0 then
		delay 5
	end if
end repeat

--once the script arrives here, the file in question is not growing and is not busy anymore 
--this has been tested for all kinds of file sizes (up to 1,2GB) and protocols (FTP, SMB) 
--now that the file is ready, begin your processing 
--you should check here if the file exists, because the Windows copy process could have been aborted by the user 

tell application “Finder”
set sourcefolder to “Macintosh HD:Users:eiki:Felles:source” as string
set destfolder to “Macintosh HD:Users:eiki:Felles:dest” as string
set filename to name of this_item as string
move item filename in folder sourcefolder to destfolder
end tell

end ProcessItem

on adding folder items to this_folder after receiving added_items
	repeat with i from 1 to the count of these_items
		set this_item to item i of these_items
		set beeldnaam to (this_item as string)
		ProcessItem(this_folder, this_item) 
	end repeat
end open

And this Folder Action Script I use for moving files, and working just fine:

on adding folder items to this_folder after receiving added_items
	tell application "Finder"
		select every item of this_folder
		move selection to folder                -- fill in destination folder
		delete selection                              -- delete file in this (old) folder
		close window of this_folder
	end tell
end adding folder items to

How does this work? Do you have two scripts attached to the folder. The first one checking if files are finished copy and the other script moving the files?

Could you please provide me with the complete script structure?

Thanks

The first script is your script with a small adjustment

The second script is the script I use for moving files (an folder action script) and that just work fine, so without any delay subroutines or something like that

I don´t know what I am doing wrong, but with your modifications to the first script (the wait untill copy script), the second script is triggered before the items are finished copying… what is the purpose of “beeldnaam” in your script? With your modifications my first script looks like this:

on adding folder items to this_folder after receiving added_items
repeat with i from 1 to the count of these_items
set this_item to item i of these_items
set beeldnaam to (this_item as string)
ProcessItem(this_folder, this_item)
end repeat
end adding folder items to

–subroutine that processes items that were added to a folder
on ProcessItem(this_folder, this_item)

--check if file is growing using UNIX "ls" command 
set LastFileSize to -1
set isGrowing to true
repeat until isGrowing is false
	set CurrentFileSize to do shell script ("/bin/ls -l " & (quoted form of (POSIX path of (this_item))) & " | /usr/bin/awk '{print $5}'")
	if CurrentFileSize is equal to LastFileSize then
		set isGrowing to false
	else
		set LastFileSize to CurrentFileSize
		delay 2
	end if
end repeat

--check if file is busy using UNIX "lsof" command 
set isbusy to 1
repeat until isbusy is 0
	set isbusy to ((do shell script ("echo `lsof " & (quoted form of (POSIX path of (this_item))) & " | wc -l`")) as integer)
	if isbusy is not equal to 0 then
		delay 5
	end if
end repeat


--once the script arrives here, the file in question is not growing and is not busy anymore 
--this has been tested for all kinds of file sizes (up to 1,2GB) and protocols (FTP, SMB) 
--now that the file is ready, begin your processing 
--you should check here if the file exists, because the Windows copy process could have been aborted by the user 

end ProcessItem

Sorry, “beeldnaam” that’s because I copy it from a script, this script is a droplett wich I use for creation of LR JPG images, beeldnaam is Dutch for imagename.
I have put about 10 files at the same time on this droplett and the script works fine.
(Files of different sizes to check te script, from small GIF files untill larger PSD or PDF files)

global mapnaam

on open these_items
tell application “Finder”
– maakt indien niet reeds bestaand map LR_JPEG aan op Desktop
– makes (if not exist) a foldermap with the name LR_JPEG on Desktop
set nieuwefoldernaam to (startup disk as string)
set mapnaam to (nieuwefoldernaam as string) & “Users:” & (nieuwefoldernaam as string) & “Desktop:LR_JPEG:”
if (not (exists folder mapnaam)) then make new folder with properties {name:“LR_JPEG”}
end tell
– repeat voor als het om meerdere files gaat
– repeat function for more then 1 file
repeat with i from 1 to the count of these_items
set this_item to item i of these_items
set beeldnaam to (this_item as string)
– test subroutine
– here he goes to the subroutine who will make LR - RGB JPG of the images
if beeldnaam is greater than “” then process_item(beeldnaam)
end repeat
end open

– here comes the subroutine for photoshop making the LR JPEG files

The second script I use for moving files (this one) :

on adding folder items to this_folder after receiving added_items
tell application “Finder”
select every item of this_folder
move selection to folder --put here your destination folder –
delete selection
close window of this_folder
end tell
end adding folder items to

This works ok on my Mac, I try to test this script with more and larger files to check if it works.
But, do I understand it correctly, your problem is that the files are being moved while there not totaly completed in the first folder (this_folder in the script)?

I think this must be the start of your script :

– variable “these_items” are all the items copied to this folder
on adding folder items to this_folder after receiving these_items
– repeat from the first file till the last file
repeat with i from 1 to the count of these_items
– variable “this_item” is the variable for a single file
set this_item to item i of these_items
– in this case the variable “beeldnaam” is the string of the variable “this_item”
set beeldnaam to (this_item as string)
– ProcessIten with “string” filename
ProcessItem(beeldnaam)
– after this the script repeats with the second added file, etc, untill the last added file
end repeat
end adding folder items to

–subroutine that processes items that were added to a folder

or this, if you don’t need a string for the subroutine “ProcessItem”

on adding folder items to this_folder after receiving added_items
repeat with i from 1 to the count of these_items
set this_item to item i of these_items
ProcessItem(this_item)
end repeat
end adding folder items to

–subroutine that processes items that were added to a folder