Bilder von CF-Karte importieren (Skript das verbessert werden will)

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
 
Der PHP-Tag mag irgendwie keine Sonderzeichen, mit dem CODE-Tag geht's. Ich habs geändert.
 
Alles entfernt - es stimmt schon scheinbar alles.
Ich habe das Jahr manuell gesetzt aber an die 2-te Bedingung nicht gedacht ;)
 
Hallo zusammen,

hier noch mal großen Dank an Pill :cake:

ich habe den Code jetzt an die Unterschiede zwischen externen Platten und FileShare angepasst.
Für erstes bin ich ja zufrieden :D
Auch wenn AS es wie fast alle andere Skriptsprachen keine Variablendeklaration verlangt, finde ich es doch etwas "übersichtlicher" wenn man es doch tut.

Jetzt MUSS Apple aber einen neuen Mini die Tage rausbringen, damit ich wirklich was vom Skript habe.

Code:
-- Allgemeine Definitionen
set bodyName to ""
set bodyNames to {"EOS5DMKIII", "EOS7D", "EOSM"}
set cardName to ""
set cardNames to {"EOS5D", "EOS7D", "EOSM"}
set diskNames to {}
set sourceDir to ""
set sourceDrive to {}
set backupImageDir to "~/Pictures/"
set backupDir to ""
set backupDrive to ""
set destinationDir to ""
set destinationDrives to {"ExtHDD 2503", "ExtHDD 2504", "ExtHDD 2505", "ExtHDD 2506", "ExtHDD 2507"}
set destinationDrive to ""
set destinationDriveName to ""
set fileName to ""
set fileList to ""
set fileDate to ""
set fileDateTag to ""
set fileDateMonat to ""
set fileDateJahr to ""
set imageDate to do shell script "date +\"%d-%m-%Y\""
set aktuellesJahr to year of (current date)
set alleJahre to {"2014", "2016", "2018", "2020", "2022"}
set osName to ""
set logFile to ""
set logFileName to ""
set logEintrag to ""
set userName to system attribute "USER"
-- Allgemeine Definitionen Ende

-- sourceDrive finden 
tell application "Finder"
	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

-- bodyName und sourceDir 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

-- wenn sourceDrive oder bodyName unbekannt/leer sind Programm beenden
if (sourceDrive is equal to "") or (bodyName is equal to "") then
	error number -128
end if

-- destinationDrive und backupDrive/ backupDir finden
tell application "Finder"
	if "Fotografie" is in diskNames then
		set destinationDrive to "Fotografie"
		repeat with i from 1 to count alleJahre
			if aktuellesJahr ≤ item i of alleJahre is true then
				set destinationDriveName to item i of destinationDrives
				exit repeat
			end if
		end repeat
	else
		repeat with i from 1 to count alleJahre
			if (aktuellesJahr ≤ 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
	
	display dialog "destinationDrive " & destinationDrive
	display dialog "destinationDriveName " & destinationDriveName
	
	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"
	set backupDrive to "Backup-" & sourceDrive & "-" & imageDate
	set backupDir to backupDrive
end tell

-- fileDate finden, in Elemente zerlegen und ins Ziel Verzeichnisse kopieren 
tell application "Finder"
	set fileList to every file of folder sourceDir
end tell
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)
	if (the fileName as string) ends with ".cr2" then
		if destinationDrive is equal to "Fotografie" then
			set destinationDir to "Volumes:" & destinationDrive & ":DSLR:" & destinationDriveName & ":" & bodyName & ":RAW:" & fileDateJahr & ":" & fileDateMonat & ":" & fileDateTag as string
		else
			set destinationDir to "Volumes:" & destinationDrive & ":" & userName & ":Fotografie:DSLR:" & destinationDriveName & ":" & bodyName & ":RAW:" & fileDateJahr & ":" & fileDateMonat & ":" & fileDateTag as string
		end if
	else if (the fileName as string) ends with ".jpeg" then
		if destinationDrive is equal to "Fotografie" then
			set destinationDir to "Volumes:" & destinationDrive & ":DSLR:" & destinationDriveName & ":" & bodyName & ":RAW:" & fileDateJahr & ":" & fileDateMonat & ":" & fileDateTag as string
		else
			set destinationDir to "Volumes:" & destinationDrive & ":" & userName & ":Fotografie:DSLR:" & destinationDriveName & ":" & bodyName & ":JPEG.CAM:" & fileDateJahr & ":" & fileDateMonat & ":" & fileDateTag as string
		end if
	else
		error number -128
	end if
	do shell script "mkdir -p " & quoted form of POSIX path of destinationDir
	tell application "Finder"
		set fileName to do shell script "echo " & fileName & " | awk -F: '{print $4}' | tr '[:upper:]' '[:lower:]'"
		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

-- backupDrive abhändgen 
if backupImageDir is equal to "~/Pictures/" then
	do shell script "hdiutil unmount /Volumes/" & backupDrive
end if

-- sourceDrive abhängen 
do shell script "hdiutil unmount /Volumes/" & sourceDrive

-- Einige Information ins logFile schreiben
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

Tobi
 
Hallo,
ich muss mein Skript etwas modifizieren und schon gibt es wieder Probleme :(
Es gibt eine Zeile
Code:
if (the fileName as string) ends with ".cr2" then
das funktioniert so weit. Diese Zeile muss ich etwas verändern. da dachte ich mir so sollte es doch richtig sein. Aber nein AS hat sofort zu meckern
Code:
if (the fileName as string) ends with (".cr2" or ".orf") then
error "\".cr2\" kann nicht in Typ boolean umgewandelt werden." number -1700 from ".cr2" to boolean
Nehme ich die Klammer weg, dann wird ".orf" angemeckert.
error "\".orf\" kann nicht in Typ boolean umgewandelt werden." number -1700 from ".orf" to boolean
Tobi

EDIT

Ob das so richtig ist weiß ich nicht. Auf jedem Fall funktioniert es so:

Code:
if ((the fileName as string) ends with ".cr2") or ((the fileName as string) ends with ".orf") then
 
Hallo,

nach langer Zeit wollte ich jetzt noch etwas an dem Skript modifizieren.
Und zwar an der Stelle:

Code:
tell application "Finder"
		set fileName to do shell script "echo " & fileName & " | awk -F: '{print $4}' | tr '[:upper:]' '[:lower:]'"
		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

Ich hätte gerne daraus ein

Code:
tell application "Finder"
		set fileName to do shell script "echo " & fileName & " | awk -F: '{print $4}' | tr '[:upper:]' '[:lower:]'"
		set name of (duplicate sourceDir & fileName to backupDir as alias) to fileName
		set name of (duplicate sourceDir & fileName to destinationDir as alias) to fileName
                
               [B]do shell script "cp -a BasisDatei.xmp fileName(OhneExtension).xmp[/B]
		do shell script "chmod 644 " & quoted form of POSIX path of (destinationDir & ":" & fileName)
		delete file (sourceDir & fileName) as alias
	end tell

Unter fileName habe ich jetzt z.B "_mg_8124.cr2". Es geht also darum die Datei "BasisDatei.xmp" nach "_mg_8124.xmp" zu kopieren.
Irgendwie kriege ich die "alte" Extension nicht ab und dafür neue dran :(
 
Code:
do shell script "cp -a BasisDatei.xmp \"${fileName%.cr2}.xmp\""

Code:
filename="${fullfile##*/}"
extension="${filename##*.}"
filename="${filename%.*}"
 
Zurück
Oben Unten