–Open this script in a new Script Editor window.
property debugMe : true
property delayTime : 10 – seconds
property fileNameList : {}
property fileSizeList : {}
property fileProcessedList : {}
property folderToProcess : missing value
on run
set folderToProcess to choose folder with prompt “Select Folder to process files”
set {fileNameList, fileSizeList, fileProcessedList} to {{}, {}, {}}
end run
on idle
try
my dd(“Checking for differences in “” & (folderToProcess as Unicode text) & “”…”)
set startTime to current date
set {newNameList, newSizeList} to my [color=green]CreateFileNameSizeLists/color
set {filesToProcess, newNewNameList, newNewSizeList} to {{}, {}, {}}
repeat with j from 1 to (count newNameList)
set {addedToListToBeProcessed, newName, newSize} to {false, newNameList’s item j, newSizeList’s item j}
repeat with i from 1 to (count fileNameList)
set {fileName, fileSize} to {fileNameList’s item i, fileSizeList’s item i}
if fileName = newName then
if newSize is not 0 and newSize = fileSize then
my dd(“Adding “” & fileName & “” to list of files to be processed…”)
set {addedToListToBeProcessed, filesToProcess’s end} to {true, fileName}
exit repeat
end if
end if
end repeat
if not addedToListToBeProcessed then
if fileProcessedList does not contain newName then
–my dd(“Adding “” & (folderToProcess as Unicode text) & newName & “” to new file lists…”)
set {newNewNameList’s end, newNewSizeList’s end} to {newName, (info for (((folderToProcess as Unicode text) & newName) as alias))'s size}
end if
end if
end repeat
set {fileNameList, fileSizeList} to {newNewNameList, newNewSizeList}
repeat with i from 1 to (count filesToProcess)
set fileProcessedList’s end to filesToProcess’s item i
end repeat
my [color=green]ProcessFiles/color
set diffTime to ((current date) - startTime)
if (diffTime is greater than or equal to delayTime) then
return 1
else
return delayTime - diffTime
end if
on error e
my dd("Error: " & e)
–set the clipboard to e
end try
end idle
on [color=green]ProcessFiles/color
repeat with i from 1 to (count theFiles)
my dd(“Processing “” & ((folderToProcess as Unicode text) & theFiles’s item i) & “”…”)
my ProcessThisFile(((folderToProcess as Unicode text) & theFiles’s item i) as alias)
end repeat
if theFiles is not {} then my dd("Number of processed items: " & (count theFiles))
end ProcessFiles
on [color=green]ProcessThisFile/color
– your file processing code goes here.
set testFolderName to “TestFolder”
my dd(“Copying Filename: “” & (info for theFile)'s name & “” to “” & testFolderName & “”…”)
tell application “Finder”
try
set testFolder to ((path to desktop folder as Unicode text) & testFolderName & “:”) as alias
on error
set testFolder to (make new folder at desktop with properties {name:testFolderName}) as alias
end try
duplicate theFile to testFolder with replacing
end tell
end ProcessThisFile
on [color=green]CreateFileNameSizeLists/color
set folderList to list folder theFolder without invisibles
set {myNameList, mySizeList} to {{}, {}}
repeat with j from 1 to (count folderList)
if (folderList’s item j)'s character 1 is not “.” then
set theInfo to info for ((theFolder as Unicode text) & (folderList’s item j) as alias)
– if (theInfo’s folder) then (*perhaps we want to copy folders *)
set {myNameList’s end, mySizeList’s end} to {theInfo’s name, theInfo’s size}
– end if
end if
end repeat
return {myNameList, mySizeList}
end CreateFileNameSizeLists
on [color=green]dd/color
if m starts with “Error:” then
activate
beep 2
if (display dialog m buttons {“Quit”, “OK”} default button 2 with icon 0)'s button returned = “Quit” then quit
else if debugMe then
activate
if (display dialog m buttons {“Quit”, “OK”} default button 2 with icon 1 giving up after 1)'s button returned = “Quit” then quit
end if
end dd