The following script watches a mountable share on a server, wwhen files are added they are then copied to another server which is set to process the files. My script (with help from others) has a timer to check when a file is put onto the server, and checks to be sure it is all there before copying it, the problems is that it lets other files into the folder without the script seeing it, so there are orphened files not moved. Any ideas on how to fix this, or to add if existing files are in the folder?
thanks, Chad
on adding folder items to this_folder after receiving added_items
repeat with aFile in added_items
repeat
set size_check1 to size of (info for aFile)
do shell script “sleep 2”
set size_check2 to size of (info for aFile)
if size_check1 is equal to size_check2 then exit repeat
end repeat
tell application "Finder"
try
set name_ to name of aFile
if name_ begins with "DT" then
if name_ contains "_cdot" then
tell application "Finder"
try
copy aFile to folder "PrinergyJobs_on_G:Prinergy Hot Folders:Dent2Day:COMPOSITE CopyDot_CMYK:"
on error err
display dialog err
end try
end tell
move aFile to folder "Pagestore:PageStore v2.3:WorkSpace:Incoming:DT_Copied:" with replacing
else if name_ contains "_spot" then
tell application "Finder"
try
copy aFile to folder "PrinergyJobs_on_G:Prinergy Hot Folders:Dent2Day:Norm_PMS:"
on error err
display dialog err
end try
end tell
move aFile to folder "Pagestore:PageStore v2.3:WorkSpace:Incoming:DT_Copied:" with replacing
else
tell application "Finder"
try
copy aFile to folder "PrinergyJobs_on_G:Prinergy Hot Folders:Dent2Day:Norm_CMYK:"
on error err
display dialog err
end try
end tell
move aFile to folder "Pagestore:PageStore v2.3:WorkSpace:Incoming:DT_Copied:" with replacing
end if
end if
end try
end tell
end repeat
The following script uses the idle handler instead of folder events. It is a good deal simpler than the script that you have, all it does is copy the file to another folder and opens it when the transfer is complete. When you run the script it will ask you which folder it should check for new files, and then it will ask you to specify the folder where you want to move the file to. Also any files in the folder when the script is started will not be processed.
I find the folder action events to not be reliable enough for this sort of thing.
Kevin
-- Any files in the sourceFolder that are there when this script
-- starts will not be processed. Error checking is not implemented.
property idleTime : 3 -- in seconds
property sourceFolder : missing value
property destinationFolder : missing value
property haveDeterminedFolders : false
property doNotProcessList : missing value
property lastTimeListNames : {}
property lastTimeListSizes : {}
on idle
if haveDeterminedFolders is equal to false then
set sourceFolder to choose folder with prompt "Select folder where images arrive: "
set destinationFolder to choose folder with prompt "Select folder where you want to move the files to: "
set haveDeterminedFolders to true
set doNotProcessList to list folder sourceFolder without invisibles
-- log (doNotProcessList)
return idleTime
end if
set thisFileList to list folder sourceFolder without invisibles
-- log (thisFileList)
set newTimeListNames to {}
set newTimeListSizes to {}
repeat with i from 1 to the count of thisFileList
set thisItem to item i of thisFileList
if thisItem is not in doNotProcessList then
set foundItem to 0
repeat with j from 1 to count of lastTimeListNames
set thisName to item j of lastTimeListNames
if thisName is equal to thisItem then
set foundItem to j
exit repeat
end if
end repeat
if foundItem is equal to 0 then
copy thisItem to the end of newTimeListNames
copy (size of (info for (((sourceFolder as string) & thisItem) as alias))) to the end of newTimeListSizes
else
set theFileItem to ((sourceFolder as string) & thisItem) as alias
if (size of (info for theFileItem)) is equal to (item foundItem of lastTimeListSizes) then
tell application "Finder"
set the source_file to (move theFileItem to the destinationFolder with replacing) as alias
open source_file
end tell
else
copy thisItem to the end of newTimeListNames
copy (size of (info for (((sourceFolder as string) & thisItem) as alias))) to the end of newTimeListSizes
end if
end if
end if
end repeat
set lastTimeListNames to newTimeListNames
set lastTimeListSizes to newTimeListSizes
return idleTime
end idle
on run
set haveDeterminedFolders to false
idle
end run
OK - i was told that having a timed delay is not a great idea for files coming into a server, and that it would be better to have the file rename itself to the same name before continuing on to the rest of the script to get moved, etc… Make any sense to anyone? And how would write that?