I’m a newbie, and I’m trying to determine if a record is in a list of records:
I fist create a list of records with this portion of script:
set bSF to bSF as alias
set aFiles to every file of bSF
repeat with aFile in aFiles
set aMod to modification date of aFile
set aUrl to aFile as alias
set row to {aUrl:aUrl, aMod:aMod}
copy row to the end of oldFiles
end repeat
Then I try to know if a record is in the list with these:
repeat with newFile in newFiles
set aMod to modification date of newFile
set aUrl to newFile
set row to {aUrl:aUrl, aMod:aMod}
if row is in oldFiles then
copy row to the end of tempFiles
set backup to true
end if
end repeat
But this fails.
I don’t know if there is another way to do this, or if I’m doing something wrong.
your script ist almost o.k, but
file and modification date are terms of the Finder,
so you need a tell block to target the Finder
set bSF to bSF as alias
tell application "Finder"
set aFiles to every file of bSF
repeat with aFile in aFiles
set aMod to modification date of aFile
set aUrl to aFile as alias
set row to {aUrl:aUrl, aMod:aMod}
copy row to the end of oldFiles
end repeat
end tell
or
set bSF to bSF as alias
tell application "Finder" to set aFiles to files of bSF
repeat with aFile in aFiles
copy {aUrl:modification date of (info for of (aFile as alias)), aMod:aFile as alias} to the end of oldFiles
end repeat
First of all, thanks for the response, but the tell finder is in my entire script:
property SF : "Macintosh HD:Users:Mac:Desktop:Prueba Backups"
property BF : "Macintosh HD:Users:Mac:Desktop:Prueba Backups:Backup Zone"
set backup01 to crearBackItUp(SF, BF)
set backup02 to crearBackItUp(SF, BF)
tell backup01 to iniciar()
tell backup01 to buscaNuevos()
tell backup02 to iniciar()
on idle
tell backup02 to buscaNuevos()
end idle
on crearBackItUp(backupSourceFolder, backupDestinyFolder)
script backItup
property bSF : backupSourceFolder
property bBF : backupDestinyFolder
property oldFiles : {}
property oldNames : {}
property backup : false
on iniciar()
tell application "Finder"
set bSF to bSF as alias
set aFiles to every file of bSF
repeat with aFile in aFiles
set aMod to modification date of aFile
set aUrl to aFile as alias
set row to {aUrl:aUrl, aMod:aMod}
copy row to the end of oldFiles
end repeat
end tell
end iniciar
on buscaNuevos()
tell application "Finder"
set backup to false
set newFiles to (every file of bSF)
set tempFiles to {}
set tempOldNames to {}
repeat with i from 1 to count of oldFiles
if ((item i of oldFiles) as record) is in newFiles then
copy item i of oldFiles to the end of tempFiles
end if
end repeat
repeat with newFile in newFiles
set aMod to modification date of newFile
set aUrl to newFile
set row to {aUrl:aUrl, aMod:aMod}
if row is not in oldFiles then
copy row to the end of tempFiles
set backup to true
end if
end repeat
display dialog (backup)
if backup is true then
set oldFiles to tempFiles
set oldNames to tempOldNames
set backup to false
end if
end tell
return backup
end buscaNuevos
on comparaMods()
tell application "Finder"
end tell
end comparaMods
end script
end crearBackItUp
Sorry, Jaime, I missunderstood your problem.
It’s not possible in AppleScript to determine values in a list of records.
I would use two separated lists instead
Thanks kel, I was sure that it must be a way to do this!!!
But now I have another trouble, I do this for searching for new files in the folder, and discard the files that was deleted, but when I do my repeat, it brings a dialog that tell that the file can´t be found.
I don’t know how to solve this.
I tried what you say to me, but with this:
repeat with newFile in newFiles
set aMod to modification date of newFile
set aUrl to newFile
set row to {aUrl:aUrl, aMod:aMod}
if {row} is not in oldFiles then
copy row to the end of tempFiles
set backup to true
end if
end repeat