I am somewhat new to Applescript (and Mac scripting/programming in general). I have been stuck on this error for quite some time now. Basically, I have two functions handling almost everything - fileList() and folderList(). I want to call these functions each 4 times, once with each of four destination folders which are passed in as parameters.
The problem is that it won’t seem to call each function more than once without erroring out (-1708). Each function call works only if there has been no call before it. Otherwise it will fail. What is the point of functions if you cannot call them more than once (and with different parameters)?
main()
on main()
set pathToPersonal to ("Macintosh HD:") & "PERSONAL"
set pathToTaxData to ("Macintosh HD:") & "TaxData"
set pathToQuickLocal to ("Macintosh HD:") & "QUICKLOCAL"
set pathToInvDocuments to ("Macintosh HD:") & "INV DOCUMENTS"
set destNamePersonal to "PERSONAL"
set destNameTaxData to "TaxData"
set destNameQuickLocal to "QUICKLOCAL"
set destNameInvDocuments to "INV DOCUMENTS"
mountVolume()
makeNewFolder()
fileList(pathToPersonal, destNamePersonal)
folderList(pathToPersonal, destNamePersonal)
fileList(pathToTaxData, destNameTaxData)
folderList(pathToTaxData, destNameTaxData)
fileList(pathToQuickLocal, destNameQuickLocal)
folderList(pathToQuickLocal, destNameQuickLocal)
fileList(pathToInvDocuments, destNameInvDocuments)
folderList(pathToInvDocuments, destNameInvDocuments)
end main
on mountVolume()
tell application "Finder"
mount volume "smb://server/D"
end tell
end mountVolume
on makeNewFolder()
tell application "Finder"
set newFolderName to date string of (current date)
try
make new folder at alias ":Volumes:Server:Backup on Server:Incremental Backups" with properties {name:newFolderName}
on error
display dialog "There is already a folder with today's date. Please backup this folder, or choose 'Continue Anyway' to overwrite." buttons {"Cancel", "Continue Anyway"}
end try
end tell
end makeNewFolder
on fileList(pathTo, nameOf)
set newFolderName to date string of (current date) as text
set sourcePath to pathTo
set halfdestPath to ":Volumes:Server:Backup on Server:Incremental Backups:" & newFolderName as alias
tell application "Finder"
set the fileList to (files of alias sourcePath) as alias list
set modDestDate to ((":Volumes:Server:Backup on Server:Incremental Backups:") & my checkDate()) as alias
set destPath to make new folder at halfdestPath with properties {name:nameOf}
repeat with currentFile in fileList
if modification date of file currentFile > modification date of modDestDate then
duplicate currentFile to destPath with replacing
end if
end repeat
end tell
end fileList
on folderList(pathTo, nameOf)
set newFolderName to date string of (current date) as text
set sourcePath to pathTo
--set halfdestPath to ":Volumes:Server:Backup on Server:Incremental Backups:" & newFolderName as alias
--set destPath to ((halfdestPath as text) & nameOf)
tell application "Finder"
set the folderList to (folders of alias sourcePath) as alias list
set modDestDate to ((":Volumes:Server:Backup on Server:Incremental Backups:") & my checkDate()) as alias
set halfdestPath to ":Volumes:Server:Backup on Server:Incremental Backups:" & newFolderName as alias
set destPath to ((halfdestPath as text) & nameOf as text) as text
--display dialog destPath as text
repeat with currentFolder in folderList
if modification date of folder currentFolder > modification date of modDestDate then
set fileList to (files of folder currentFolder) as alias list
set the deepfolderList to (folders of folder currentFolder) as alias list
set nameFolder to name of currentFolder
set makeNewFolder to make new folder at destPath with properties {name:nameFolder}
repeat with currentFile in fileList
if modification date of file currentFile > modification date of modDestDate then
duplicate currentFile to makeNewFolder with replacing
end if
end repeat
repeat with deepcurrentFolder in deepfolderList
if modification date of folder deepcurrentFolder > modification date of modDestDate then
set deepnameFolder to name of folder deepcurrentFolder
set deepnewFolderDest to (destPath) & ":" & (name of currentFolder as text)
set makedeepNewFolder to make new folder at (deepnewFolderDest as text) with properties {name:deepnameFolder}
set deepfileList to (files of folder deepcurrentFolder) as alias list
repeat with deepcurrentFile in deepfileList
if modification date of file deepcurrentFile > modification date of modDestDate then
duplicate deepcurrentFile to makedeepNewFolder with replacing
end if
end repeat
end if
end repeat
end if
end repeat
end tell
end folderList
on checkDate()
tell application "Finder"
set theCheckDateItems to every folder of alias ":Volumes:Server:Backup on Server:Incremental Backups"
set theCheckDateItems to (sort theCheckDateItems by modification date)
set theCheckDateNames to {}
set theCheckDateBack to the reverse of theCheckDateItems
repeat with oneCheckDateFile in theCheckDateBack
set beginning of theCheckDateNames to name of oneCheckDateFile
end repeat
end tell
set comparisonDate to second item of theCheckDateNames
return comparisonDate
end checkDate