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

ObiTobi

ObiTobi

Aktives Mitglied
Thread Starter
Dabei seit
05.11.2009
Beiträge
1.536
Reaktionspunkte
91
Hallo,

wie schon in anderem Thread angekündigt, hier mein kleines Skript welches Bilder von der CF-Karte auf externe Platte (oder Netzlaufwerk <- ist leider noch nicht implementiert) kopiert. Dabei
- direkt einen Backup in ein erzeugtes Sparsebundle macht
- die Dateinamen in Kleinbuchstaben beim Kopieren umbenennt
- die Dateien in eine automatisch erzeugte Verzeichnisstruktur kopiert


PHP:
-- Kopiert RAW und JPEG Dateien vom Datenträger (CF-Karte) auf Externe Platte oder Netzlaufwerk wenn vorhanden.

set bodyNames to {"EOS5DMKIII", "EOS7D", "EOSM"}
set bodyName to ""
set cardName to ""
set cardNames to {"EOS5D-001", "EOS5D-002", "EOS7D-001", "EOS7D-002", "EOSM-001", "EOSM-002"}

set driveName to ""
set drivenames to ""

set sourceDir to ""
set sourceDrive to ""

set backupDir to ""
set backupImageDir to ""
set backupDrive to ""
set destinationDir to ""
set destinationDrives to {"ExtHDD 2503", "ExtHDD 2504", "ExtHDD 2505", "ExtHDD 2506", "ExtHDD 2507"}
set destinationDrive to ""

set nextFile to ""
set fileName to ""
set fileList to ""
set fileDate to ""

set imageDate to do shell script "date +\"%d-%m-%Y\""
set aktuellesJahr to year of (current date)

set osName to ""

set logFile to ""
set logFileName to ""
set logEintrag to ""

set userName to system attribute "USER"

tell application "Finder"
	set osName to do shell script "sw_vers -productVersion"
end tell
if osName is not "10.8.5" then
	display dialog "Programm wird beendet"
end if

-- SourceDrive finden
tell application "Finder" to set drivenames to name of every disk
repeat with driveName in driveNames
	if driveName is in cardNames then
		set sourceDrive to driveName
	end if
end repeat

-- Body finden
tell application "Finder"
	if (exists disk (item 1 of cardNames)) or (exists disk (item 2 of cardNames)) then
		set bodyName to item 1 of bodyNames
		set sourceDir to alias "Volumes:" & sourceDrive & ":dcim:100eos5d:" as string
	else if (exists disk (item 3 of cardNames)) or (exists disk (item 4 of cardNames)) then
		set bodyName to item 2 of bodyNames
		set sourceDir to alias "Volumes:" & sourceDrive & ":dcim:100eos7d:" as string
	else if (exists disk (item 5 of cardNames)) or (exists disk (item 6 of cardNames)) then
		set bodyName to item 3 of bodyNames
		set sourceDir to alias "Volumes:" & sourceDrive & ":dcim:100eosm:" as string
	else
		error number -128
	end if
end tell

-- DestinationDrive und Backup finden und festlegen
tell application "Finder"
	if exists disk "Fotografie-2" then
		set destinationDrive to "Fotografie-2"
	else if (exists disk (item 1 of destinationDrives)) or (exists disk (item 2 of destinationDrives)) or (exists disk (item 3 of destinationDrives)) or (exists disk (item 4 of destinationDrives)) or (exists disk (item 5 of destinationDrives)) then
		if aktuellesJahr ≤ "2014" then
			set destinationDrive to item 1 of destinationDrives
		else if aktuellesJahr ≤ "2016" then
			set destinationDrive to item 2 of destinationDrives
		else if aktuellesJahr ≤ "2018" then
			set destinationDrive to item 3 of destinationDrives
		else if aktuellesJahr ≤ "2020" then
			set destinationDrive to item 4 of destinationDrives
		else if aktuellesJahr ≤ "2022" then
			set destinationDrive to item 5 of destinationDrives
		end if
	else
		error number -128
	end if
	set backupImageDir to "~/Pictures/"
	do shell script "hdiutil create " & "-fs HFS+ " & backupImageDir & sourceDrive & "-`date +\"%d-%m-%Y\"`.sparsebundle -volname " & sourceDrive & "-`date +\"%d-%m-%Y\"`"
	do shell script "hdiutil attach " & backupImageDir & sourceDrive & "-`date +\"%d-%m-%Y\"`.sparsebundle"
	set backupDrive to 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)
	WrtiteLogFile("fileName ist " & fileName & " Tag ist " & fileDateTag & " Monat ist " & fileDateMonat & " Jahr ist " & fileDateJahr)
	tell application "System Events"
		if not (exists folder (destinationDrive & ":" & userName & ":Fotografie:DSLR:" & bodyName & ":RAW:" & fileDateJahr)) then
			tell application "Finder"
				make new folder with properties {name:fileDateJahr} at folder "RAW" of folder bodyName of folder "DSLR" of folder "Fotografie" of folder userName of disk destinationDrive
			end tell
		end if
		if not (exists folder (destinationDrive & ":" & userName & ":Fotografie:DSLR:" & bodyName & ":RAW:" & fileDateJahr & ":" & fileDateMonat)) then
			tell application "Finder"
				make new folder with properties {name:fileDateMonat} at folder fileDateJahr of folder "RAW" of folder bodyName of folder "DSLR" of folder "Fotografie" of folder userName of disk destinationDrive
			end tell
		end if
		if not (exists folder (destinationDrive & ":" & userName & ":Fotografie:DSLR:" & bodyName & ":RAW:" & fileDateJahr & ":" & fileDateMonat & ":" & fileDateTag)) then
			tell application "Finder"
				make new folder with properties {name:fileDateTag} at folder fileDateMonat of folder fileDateJahr of folder "RAW" of folder bodyName of folder "DSLR" of folder "Fotografie" of folder userName of disk destinationDrive
			end tell
		end if
	end tell
	set destinationDir to alias "Volumes:" & destinationDrive & ":" & userName & ":Fotografie:DSLR:" & bodyName & ":RAW:" & fileDateJahr & ":" & fileDateMonat & ":" & fileDateTag as string
	tell application "Finder"
		set fileName to do shell script "echo " & fileName & " | awk -F: '{print $4}'"
		set fileName to do shell script "echo " & fileName & " | 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

-- 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

WrtiteLogFile("sourceDrive ist " & sourceDrive)
WrtiteLogFile("sourceDir ist " & sourceDir)
WrtiteLogFile("bodyName ist " & bodyName)
WrtiteLogFile("destinationDrive ist " & destinationDrive)
WrtiteLogFile("destinationDir ist " & destinationDir)
WrtiteLogFile("backupDrive ist " & backupDrive)
WrtiteLogFile("backupDir ist " & backupDir)
WrtiteLogFile("backupImageDir ist " & backupImageDir)

-- LogFile Erzeugen und schreiben
on WrtiteLogFile(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 WrtiteLogFile
 
Was finde ich also in dem Skript nicht so toll?

- der gesamte Aufbau finde ich nicht gerade optimal. Das resultiert in erster Linie daraus, dass ich gerade an der AS Oberfläche etwas geschnuppert habe und somit das Skript "so Stückweise" entstanden ist

Viele Sachen sind mir bei AS überhaupt nicht klar - kann man aus einem "tell application xyz" keine Funktion die im Skript definiert ist aufrufen? Ist mir zumindest nicht gelungen das schreiben von meinem LogFile aus so einem Block zu machen.
Ich habe das Skript bereits mehrfach laufen lassen. An sich läuft alles ohne Probleme ABER - als ich 2 Versuche gemacht habe mit karten auf den etwas über 1000 Bilder drauf waren, ist mir der AS Editor abgestürzt. Ob das jetzt an dem Editor selbst liegt oder suboptimalen Aufbau vom Skript selbst weiß ich nicht.

Ich wollte in einem Skript entweder auf Netzlaufwerk oder externe Platte schreiben. Dummerweise habe ich auf dem Netzlaufwerk (wegen Synchronisation mit den externen Platten) an einer Stelle andere Verzeichnisstruktur als auf den Platten selbst. Das könnte ich vielleicht etwas "relativieren" wenn ich einige Blöcke als Funktion definieren könnte. Dafür musste es aber wieder möglich sein eine Funktion aus einem tell Block aufzurufen.

Wenn jemand also guten Vorschlag hat ...her damit.

Tobi
 
Man kann einen Handler auch innerhalb eines tell-Blocks aufrufen. Ein Handler ist nichts anderes als ein Befehl für dein Programm, den du geschrieben hast. Wenn du dich nun in einem tell-Block eines anderen Programm befindest, z.B. dem Finder, dann erkennt der Finder nur seine eigenen Befehle. Du musst also genau sagen, zu welchem Programm der Befehl gehört. So geht's:

Code:
tell app "Finder"
--blah
my meinHandler()
--oder
meinHandler() of me
end tell

on meinHandler()
--blubb
end meinHandler

my/me bezieht sich dabei auf dein Programm/Skript.

Ich habe mir mal den ersten Teil deines Skripts angeschaut. Die if-Abfragen sind recht umständlich, das lässt sich klug umgehen. Folgende Lösung ist nicht unbedingt die Beste, zeigt dir aber vielleicht noch die ein oder andere Möglichkeit in AppleScript:

Code:
[B]set [/B][COLOR=#4F8F00][FONT=Verdana]bodyNames [/FONT][/COLOR][B]to[/B][FONT=Verdana] {"EOS5DMKIII", "EOS7D", "EOSM"}
[/FONT][FONT=Verdana][B]set[/B] [COLOR=#4f8f00]cardNames[/COLOR] [B]to[/B] {"EOS5D", "EOS7D", "EOSM"} [COLOR=#5e6161]--Geändert[/COLOR][/FONT]
[FONT=Verdana][B]set[/B] [COLOR=#4f8f00]destinationDrives[/COLOR] [B]to[/B] {"ExtHDD 2503", "ExtHDD 2504", "ExtHDD 2505", "ExtHDD 2506", "ExtHDD 2507"}[/FONT]
[FONT=Verdana][B]set[/B] [COLOR=#4f8f00]imageDate[/COLOR] [B]to[/B] [COLOR=#012fbe][B]do shell script[/B][/COLOR] "date +\"%d-%m-%Y\""[/FONT]
[FONT=Verdana][B]set[/B] [COLOR=#4f8f00]aktuellesJahr[/COLOR] [B]to[/B] [COLOR=#812fdc]year[/COLOR] [B]of[/B] ([COLOR=#012fbe][B]current date[/B][/COLOR])[/FONT]
[COLOR=#012FBE][FONT=Verdana][COLOR=#000000][B]set[/B] [/COLOR][COLOR=#4f8f00]userName[/COLOR][COLOR=#000000] [B]to[/B] [/COLOR][B]system attribute[/B][COLOR=#000000] "USER"[/COLOR][/FONT][/COLOR]
[FONT=Verdana]
[/FONT]
[COLOR=#5E6161][FONT=Verdana]-- SourceDrive finden [/FONT][/COLOR]
[COLOR=#5E6161][FONT=Verdana]--Geändert[/FONT][/COLOR]
[FONT=Verdana][B]tell[/B] [COLOR=#0433ff][I]application[/I][/COLOR] "Finder"[/FONT]
[FONT=Verdana]    [B]set[/B] [COLOR=#4f8f00]sourceDrive[/COLOR] [B]to[/B] {}[/FONT]
[FONT=Verdana]    [B]repeat[/B] [B]with[/B] [COLOR=#4f8f00]cardName[/COLOR] [B]in[/B] [COLOR=#4f8f00]cardNames[/COLOR][/FONT]
[FONT=Verdana]        [B]set[/B] [B]end[/B] [B]of[/B] [COLOR=#4f8f00]sourceDrive[/COLOR] [B]to[/B] ([COLOR=#0433ff][I]disks[/I][/COLOR] [B]whose[/B] [COLOR=#812fdc]name[/COLOR] [B]contains[/B] ([B]get[/B] [COLOR=#4f8f00]cardName[/COLOR])) [B]as[/B] [COLOR=#0433ff][I]string[/I][/COLOR][/FONT]
[FONT=Verdana]    [B]end[/B] [B]repeat[/B][/FONT]
[COLOR=#4F8F00][FONT=Verdana][COLOR=#000000]    [B]set[/B] [/COLOR]sourceDrive[COLOR=#000000] [B]to[/B] [/COLOR]sourceDrive[COLOR=#000000] [B]as[/B] [/COLOR][COLOR=#0433ff][I]string[/I][/COLOR][/FONT][/COLOR]
[FONT=Verdana][B]end[/B] [B]tell[/B][/FONT]
[FONT=Verdana]
[/FONT]
[COLOR=#5E6161][FONT=Verdana]-- Body finden [/FONT][/COLOR]
[COLOR=#5E6161][FONT=Verdana]--Geändert[/FONT][/COLOR]
[FONT=Verdana][B]tell[/B] [COLOR=#0433ff][I]application[/I][/COLOR] "Finder"[/FONT]
[FONT=Verdana]    [B]set[/B] [COLOR=#4f8f00]diskNames[/COLOR] [B]to[/B] ([COLOR=#012fbe][B]list disks[/B][/COLOR]) [B]as[/B] [COLOR=#0433ff][I]string[/I][/COLOR][/FONT]
[FONT=Verdana]    [B]repeat[/B] [B]with[/B] [COLOR=#4f8f00]i[/COLOR] [B]from[/B] 1 [B]to[/B] [COLOR=#0433ff][B]count[/B][/COLOR] [COLOR=#4f8f00]cardNames[/COLOR][/FONT]
[FONT=Verdana]        [B]if[/B] [COLOR=#4f8f00]diskNames[/COLOR] [B]contains[/B] [COLOR=#0433ff][I]item[/I][/COLOR] [COLOR=#4f8f00]i[/COLOR] [B]of[/B] [COLOR=#4f8f00]cardNames[/COLOR] [B]then[/B][/FONT]
[COLOR=#4F8F00][FONT=Verdana][COLOR=#000000]            [B]set[/B] [/COLOR]bodyName[COLOR=#000000] [B]to[/B] [/COLOR][COLOR=#0433ff][I]item [/I][/COLOR]i[COLOR=#000000] [B]of[/B] [/COLOR]bodyNames[/FONT][/COLOR]
[FONT=Verdana]            [B]set[/B] [COLOR=#4f8f00]sourceDir[/COLOR] [B]to[/B] "Volumes:" & [COLOR=#4f8f00]sourceDrive[/COLOR] & "dcim:100" & [COLOR=#0433ff][I]item[/I][/COLOR] [COLOR=#4f8f00]i[/COLOR] [B]of[/B] [COLOR=#4f8f00]cardNames[/COLOR] & ":" [B]as[/B] [COLOR=#0433ff][I]string[/I][/COLOR][/FONT]
[FONT=Verdana]        [B]end[/B] [B]if[/B][/FONT]
[FONT=Verdana]    [B]end[/B] [B]repeat[/B][/FONT]
[B]end [/B][B]tell[/B]

Es ist in AppleScript übrigens nicht nötig alle Variablen vor der Benutzung zu initialisieren, das macht es nur unübersichtlich (meiner Meinung nach).
 
  • Gefällt mir
Reaktionen: ObiTobi
Super, danke.

Damit sieht das schon etwas anders aus.


Tobi
 
Achtung: Das geänderte »SourceDrive finden« baut jetzt eine Liste zusammen.
Wenn mehr als eine Card gemountet ist, bekommst du z.B. "EOS5D:EOS7D:", vorher war es nur die zuletzt gefundene Card.
 
Ja und nein :D
An sich hast Du ja recht, allerdings
- wusste ich nicht dass es Reader gibt die mehr als eine CF karte gleichzeitig bedienen können
- Nach dem das Script gelaufen ist bzw. nach dem alle Bilder verschoben sind, wird die Karte "unmounted"

Aber danke für den Hinweis.

Tobi
 
Nach dem ich es jetzt versucht habe umzusetzen, stelle ich doch fest, dass es nicht so ganz einfach ist.
Also die Änderungen von Pill sind schon sicherlich Sinnvoll nur..

Code:
-- SourceDrive finden 
--Geändert
tell application "Finder"
    set sourceDrive to {}
    repeat with cardName in cardNames
        set end of sourceDrive to (disks whose name contains (get cardName)) as string
    end repeat
    set sourceDrive to sourceDrive as string
end tell

Und hier gibt es für mich ein kleines Problem, welches ich aber nicht gelöst kriege

im sourceDrive steht z.B "EOS7D-001:"

Und dieses ":" ist gar nicht gut. Im späteren Verlauf des Skriptes will ich z.B das Laufwerk unmounten. Da geht nicht weil Laufwerk mit ":" am Ende gibt es nicht.
Kriegt man das irgendwie in Griff?

Tobi
 
Das lässt sich natürlich beheben.

Hier nochmal das ganze Skript. Ich habe noch ein paar andere Dinge geändert. Das ist allerdings alles ungetestet, da das Anlegen einer Testumgebung in diesem Fall doch recht aufwendig ist. Ich hoffe also, dass das Skript noch das macht, was es soll ;)

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 2503", "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 --Geändert
set userName to system attribute "USER"

-- SourceDrive finden 
--Geändert
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 
--Geändert
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"
    --Geändert
    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 ≤ item i of alleJahre) & (item i of destinationDrives is in diskNames) is {true, true} then
                set destinationDrive 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 & sourceDrive & "-$(date +\"%d-%m-%Y\").sparsebundle -volname " & sourceDrive & "-$(date +\"%d-%m-%Y\"); hdiutil attach " & backupImageDir & sourceDrive & "-$(date +\"%d-%m-%Y\").sparsebundle" --Geändert
    set backupDrive to sourceDrive & "-" & imageDate
    set backupDir to backupDrive
end tell


-- Datum finden 
tell application "Finder" to set fileList to every file of (sourceDir as alias)
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 & ":FotografieSLR:" & 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
 
Zuletzt bearbeitet:
Finders "disks" liefert Apple-Pfade.

Das Mehrkartenmount-Problem ist bei dir ja (noch) keines, also könntest du es vereinfacht wieder so schreiben:

Code:
[COLOR=#349600][COLOR=#000000][B]set[/B] [/COLOR]drivenames[COLOR=#000000] [B]to[/B] [/COLOR][COLOR=#0000c2][B]list disks[/B][/COLOR][/COLOR]
[COLOR=#349600][COLOR=#000000][B]repeat[/B] [B]with[/B] [/COLOR]driveName[COLOR=#000000] [B]in[/B] [/COLOR]drivenames[/COLOR]
[COLOR=#349600][COLOR=#000000]    [B]if[/B] [/COLOR]driveName[COLOR=#000000] [B]is[/B] [B]in[/B] [/COLOR]cardNames[COLOR=#000000] [B]then[/B][/COLOR][/COLOR]
[COLOR=#349600][COLOR=#000000]        [B]set[/B] [/COLOR]sourceDrive[COLOR=#000000] [B]to[/B] [/COLOR]driveName[COLOR=#000000] [B]as[/B] [/COLOR][COLOR=#0000ff][I]string[/I][/COLOR][/COLOR]
    [B]end[/B] [B]if[/B]
[B]end[/B] [B]repeat[/B]
 
@Olivetti: Ich habe den Inhalt von cardNames geändert. Es gibt insgesamt 6 Speicherkarten, 2 pro Kamera-Body. Die zum Body gehörigen Speicherkarten enthalten einen string, der auch im Namen des Bodys vorkommt. Dadurch kann ich im Abschnitt "Body finden" mit diese Strings mit einer Schleife durchgehen. Daher dieses "Konstrukt".
 
Hi,

Danke.
Es funktioniert allerdings nicht.

Code:
-- Body finden 
--Geändert
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 "Volumes:" & sourceDrive & ":dcim:100" & item i of cardNames & ":" as string
		end if
	end repeat
	display dialog "DISKNAMES " & diskNames
end tell


-- DestinationDrive und Backup finden und festlegen 
tell application "Finder"
	--Geändert
	if "Fotografie-2" is in diskNames then
		set destinationDrive to "Fotografie-2"
	else
		set alleJahre to {"2013", "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
	display dialog "DEST " & destinationDrive
	if destinationDrive is "" then return

destinationDrive ist leer und damit steigt das hier aus.


Hier das Ergebnis
Code:
tell application "Finder"
	get every disk whose name contains "EOS5D"
		--> {}
	get every disk whose name contains "EOS7D"
		--> {disk "EOS7D-002"}
	get every disk whose name contains "EOSM"
		--> {}
	get name of disk "EOS7D-002"
		--> "EOS7D-002"
	list disks
		--> error number -10004
end tell
tell current application
	list disks
		--> {"Macintosh HD", "MobileBackups", "home", "net", "ExtHDD 2502", "ExtHDD 2503", "EOS7D-002"}
end tell
tell application "Finder"
	display dialog "DISKNAMES Macintosh HDMobileBackupshomenetExtHDD 2502ExtHDD 2503EOS7D-002"
		--> {button returned:"OK"}
	display dialog "DEST "
 
Also diesen Part verstehe ich nicht wirklich :confused:

Code:
set alleJahre to {"2013", "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

Wenn aktuellesJahr einem Eintrag aus der alleJahre entspricht und ein Eintrag aus destinationDrives ist in der diskNames Liste
So war die Idee oder?

Tobi
 
geht etwas weiter, kommt aber das Problem was Olivetti angesprochen hat.
Es wird versucht wenn ich es richtig verstanden habe nicht von der CF Karte zu lesen, sondern von dem Sparsebundle was gerade angelegt worden ist.


Code:
tell application "Finder"
	do shell script "hdiutil create -fs HFS+ ~/Pictures/EOS7D-002-$(date +\"%d-%m-%Y\").sparsebundle -volname EOS7D-002-$(date +\"%d-%m-%Y\"); hdiutil attach ~/Pictures/EOS7D-002-$(date +\"%d-%m-%Y\").sparsebundle"
		--> error number -10004
end tell
tell current application
	do shell script "hdiutil create -fs HFS+ ~/Pictures/EOS7D-002-$(date +\"%d-%m-%Y\").sparsebundle -volname EOS7D-002-$(date +\"%d-%m-%Y\"); hdiutil attach ~/Pictures/EOS7D-002-$(date +\"%d-%m-%Y\").sparsebundle"
		--> "created: /Users/robert/Pictures/EOS7D-002-19-10-2013.sparsebundle
/dev/disk5          	GUID_partition_scheme          	
/dev/disk5s1        	EFI                            	
/dev/disk5s2        	Apple_HFS                      	/Volumes/EOS7D-002-19-10-2013"
end tell
tell application "Finder"
	get every file of folder "Volumes:EOS7D-002:dcim:100EOS7D:"
		--> error number -1728 from folder "Volumes:EOS7D-002:dcim:100EOS7D:"
Ergebnis:
error "„Finder“ hat einen Fehler erhalten: „folder \"Volumes:EOS7D-002:dcim:100EOS7D:\"“ kann nicht gelesen werden." number -1728 from folder "Volumes:EOS7D-002:dcim:100EOS7D:"
 
OK, ich habe das Backup Image etwas anderes genannt "Backup-" voreingestellt.

geht trotzdem nicht.

Code:
tell current application
	do shell script "hdiutil create -fs HFS+ ~/Pictures/Backup-EOS7D-002-$(date +\"%d-%m-%Y\").sparsebundle -volname EOS7D-002-$(date +\"%d-%m-%Y\"); hdiutil attach ~/Pictures/Backup-EOS7D-002-$(date +\"%d-%m-%Y\").sparsebundle"
		--> "created: /Users/robert/Pictures/Backup-EOS7D-002-19-10-2013.sparsebundle
/dev/disk5          	GUID_partition_scheme          	
/dev/disk5s1        	EFI                            	
/dev/disk5s2        	Apple_HFS                      	/Volumes/EOS7D-002-19-10-2013"
end tell
tell application "Finder"
	get every file of folder "Volumes:EOS7D-002:dcim:100EOS7D:"
		--> error number -1728 from folder "Volumes:EOS7D-002:dcim:100EOS7D:"
Ergebnis:
error "„Finder“ hat einen Fehler erhalten: „folder \"Volumes:EOS7D-002:dcim:100EOS7D:\"“ kann nicht gelesen werden." number -1728 from folder "Volumes:EOS7D-002:dcim:100EOS7D:"
 
OK scheinbar gefunden.

Die Zeile:

Code:
set sourceDir to alias "Volumes:" & sourceDrive & ":dcim:100" & item i of cardNames & ":" as string
musste ich verändern "alias" hinzugefügt wie in meinem Ursprünglichen Skript.
 
Der Teil sorgt dafür, dass 2013 (ursprünglich stand da 2014?) als destinationDrive "ExtHDD 2503" gesetzt wird, 2016 "ExtHDD 2504", 2018 "ExtHDD 2503" usw.

Dazu benutze ich eine Schleife, die von 1 hochzählt und eine if-Abfrage mit 2 Bedingungen, die beide wahr sein müssen. Die erste Bedingung sorgt dafür, dass
die Laufzahl der Position des aktuellen Jahres in der Liste alleJahre entspricht. Die zweite Bedingung sorgt dafür, dass die externe Festplatte an Position i auch angeschlossen ist.

Wenn das nicht das ist, was der Abschnitt "DestinationDrive und Backup finden und festlegen" machen soll, dann habe ich dich wohl missverstanden.

Ich habe in #8 mal das "as string" und das "alias" noch hinzugefügt.
 
Hallo Pill,

an sich ist das "fast" richtig.
In meinem Skript stand aber "wenn Jahr kleiner/ gleich 2014 dann ExtHDD 2503".

Jetzt merke ich selbst meinen Fehler :)

Ich "verbrauche" in etwa eine Externe Platte alle 2 Jahre

Es musste also in etwa so aussehen

Jahr kleiner/ gleich 2014 dann EXTHDD 2503
Jahr 2015 oder 2016 dann ExtHDD 2504

usw.
 
≤ is hinzugefügt in #8
 
Da hast Dich wohl vertippt

if (aktuellesJahr & #8804;

ist sicherlich nicht das was Du einfügen wolltest oder?
 
Zurück
Oben Unten