ObiTobi
Aktives Mitglied
Thread Starter
- Dabei seit
- 05.11.2009
- Beiträge
- 1.536
- Reaktionspunkte
- 91
Hier noch mal der Stand der an sich funktioniert aber das <= "Problem" hat
Code:
-- Kopiert RAW und JPEG Dateien vom Datenträger (CF-Karte) auf Externe Platte oder Netzlaufwerk wenn vorhanden.
set bodyNames to {"EOS5DMKIII", "EOS7D", "EOSM"}
set cardNames to {"EOS5D", "EOS7D", "EOSM"} --Geändert
set destinationDrives to {"ExtHDD 2502", "ExtHDD 2504", "ExtHDD 2505", "ExtHDD 2506", "ExtHDD 2507"}
set imageDate to do shell script "date +\"%d-%m-%Y\""
set aktuellesJahr to year of (current date) as string
set userName to system attribute "USER"
-- SourceDrive finden
tell application "Finder"
set sourceDrive to {}
repeat with cardName in cardNames
set sourceDrive to sourceDrive & (disks whose name contains (get cardName))
end repeat
set sourceDrive to name of item 1 of sourceDrive
end tell
-- Body finden
tell application "Finder"
set diskNames to (list disks) as string
repeat with i from 1 to count cardNames
if diskNames contains item i of cardNames then
set bodyName to item i of bodyNames
set sourceDir to alias "Volumes:" & sourceDrive & ":dcim:100" & item i of cardNames & ":" as string
end if
end repeat
end tell
-- DestinationDrive und Backup finden und festlegen
tell application "Finder"
if "Fotografie-2" is in diskNames then
set destinationDrive to "Fotografie-2"
else
set alleJahre to {"2014", "2016", "2018", "2020", "2022"}
repeat with i from 1 to count alleJahre
if (aktuellesJahr is item i of alleJahre) & (item i of destinationDrives is in diskNames) is {true, true} then
set destinationDrive to item i of destinationDrives
set destinationDriveName to item i of destinationDrives
exit repeat
else
set destinationDrive to ""
end if
end repeat
end if
if destinationDrive is "" then return
set backupImageDir to "~/Pictures/"
do shell script "hdiutil create " & "-fs HFS+ " & backupImageDir & "Backup-" & sourceDrive & "-$(date +\"%d-%m-%Y\").sparsebundle -volname Backup-" & sourceDrive & "-$(date +\"%d-%m-%Y\"); hdiutil attach " & backupImageDir & "Backup-" & sourceDrive & "-$(date +\"%d-%m-%Y\").sparsebundle" --Geändert
set backupDrive to "Backup-" & sourceDrive & "-" & imageDate
set backupDir to backupDrive
end tell
-- Datum finden
tell application "Finder" to set fileList to every file of folder sourceDir
repeat with fileName in fileList
set fileDate to modification date of fileName
set fileDateTag to text -2 thru -1 of ("0" & fileDate's day)
set fileDateMonat to text -2 thru -1 of ("0" & ((month of fileDate) * 1))
set fileDateJahr to ((year of fileDate) as text)
WriteLogFile("fileName ist " & fileName & " Tag ist " & fileDateTag & " Monat ist " & fileDateMonat & " Jahr ist " & fileDateJahr)
set destinationDir to "Volumes:" & destinationDrive & ":" & userName & ":Fotografie:" & destinationDriveName & ":DSLR:" & bodyName & ":RAW:" & fileDateJahr & ":" & fileDateMonat & ":" & fileDateTag as string
do shell script "mkdir -p " & quoted form of POSIX path of destinationDir --Geändert
tell application "Finder"
set fileName to do shell script "echo " & fileName & " | awk -F: '{print $4}' | tr '[:upper:]' '[:lower:]'" --Geändert
set name of (duplicate sourceDir & fileName to backupDir as alias) to fileName
set name of (duplicate sourceDir & fileName to destinationDir as alias) to fileName
do shell script "chmod 644 " & quoted form of POSIX path of (destinationDir & ":" & fileName)
delete file (sourceDir & fileName) as alias
end tell
end repeat
-- Backup Image abhändgen
if backupImageDir is equal to "~/Pictures/" then
do shell script "hdiutil unmount /Volumes/" & backupDrive
end if
-- CF karte abhängen
do shell script "hdiutil unmount /Volumes/" & sourceDrive
WriteLogFile("sourceDrive ist " & sourceDrive)
WriteLogFile("sourceDir ist " & sourceDir)
WriteLogFile("bodyName ist " & bodyName)
WriteLogFile("destinationDrive ist " & destinationDrive)
WriteLogFile("destinationDir ist " & destinationDir)
WriteLogFile("backupDrive ist " & backupDrive)
WriteLogFile("backupDir ist " & backupDir)
WriteLogFile("backupImageDir ist " & backupImageDir)
-- LogFile Erzeugen und schreiben
on WriteLogFile(txt)
set logFileName to "DigiCam.log"
set logPath to ((path to home folder as string) & "Library:Logs")
set logFile to open for access file (logPath & ":" & logFileName) with write permission
try
set logEintrag to short date string of (current date) & " - " & time string of (current date) & " " & (txt as text) & return
write logEintrag & return to logFile starting at eof
close access logFile
return logEintrag
on error
close access logFile
return "Error writing to logFile "
end try
end WriteLogFile