Skript: Kopieren aller Metadaten von einem Bild auf andere Bilder (macOS 14 oder neuer)

von: 
Zuletzt geändert: 27. Dez. 2024 10:20
2 257 Zuletzt geändert 27. Dez. 2024 10:20

In Aperture gibt es das grossartige "Lift& Stamp" Werkzeug, das uns ausgewählte Metadaten in Stapelverarbeitung auf andere Fotos stempeln lässt. Dieses fehlt in Fotos. Daher ist es umständlich, alle Metadaten zu restaurieren, wenn wir ein Foto exportieren und in einem externen Editor bearbeiten, der nicht von Fotos unterstützt wird, oder wenn viele gescannte Bilder dieselben Metadaten bekommen sollen.

Wir können das mit einem Applescript etwas erleichtern. Ein Skript kann einige Metadaten von einem Foto lesen und in anderen Fotos setzen. Wir können den Titel, die Beschreibung, den Dateinamen, das Aufnahmedatum und die Uhrzeit, die Schlüsselworte, die GPS Koordinaten (Länge, Breite, Höhe) lesen. Der Dateiname kann nicht überschrieben werden, auch nicht die Höhe.Hier ist ein kleines Skript, das den Titel, die Beschreibung, das Aufnahmedatum und die Uhrzeit, die Schlüsselworte, die GPS Koordinaten (Länge, Breite) von einem ausgewählten Foto liest (das zuerst ausgewählte) und dann die entsprechenden Metadaten für die anderen ausgewählten Fotos auf denselben Wert setzt.


Das Skript wird wie folgt benutzt:

  • Am besten lege ein Album mit allen Fotos an, für die die Metadaten geändert werden sollen. Das Foto, von dem die Metadaten kopiert werden sollen, sollte das erste Foto im Album sein.
  • Nun wähle alle Fotos im Album aus - zuerst die Vorlage , von der kopiert werden sollen, dann halte die Umschalttaste ⇧ gedrückt und wähle das letzt Foto aus.
  • Jetzt öffne das Skript im Skripteditor und klicke die "Run" Taste, um das Skript zu starten.


Alle ausgewählten Fotos werden jetzt denselben Titel, Beschreibung, Schlagworte, Aufnahmezeit, GPS Koordinaten haben. Falls das ausgewählte Foto keinen Titel hat, wird das Titelfeld auf den Dateinamen geändert.Damit die Fotos nach der Aufnahmezeit sortiert werden können, wird die Uhrzeit für jedes Foto eine Sekunde später sein als für das vorherige Foto. Das kann abgestellt werden, indem die Variable timeIncrement im Skript auf 0 gesetzt wird.

Wenn jemand das Skript ausprobieren will, würde ich es sicherheitshalber erst auf einer separaten Testmediathek ausprobieren. Und immer eine Sicherheitskopie der Mediathek machen, bevor ein Skript darauf losgelassen wird!


-- ✄-✄-✄-✄-✄-✄-✄-✄  snip : copy from the code box below this line  ✄-✄-✄-✄-✄-✄-✄-✄-✄
(* Batch Lift and stamp the metadata of selected photos all at once. 
The script copies the date and time, the title, the description, the keywords, the GPS location


How to use this script:
- Collect all photos you want to set to the same metadata in an album and sort them manually. ¬
 The image you want to copy the metadata from needs to be the first image in the album.
- Adjust the time and other metadata of the first of your batch of photos with "Adjust Date and time" ¬
 in Photos from the "Image" menu, even if the time is correct, to ensure theversion has a time stamp
- Select  the first photo , the hold down the Shift key and select all photos you want to set ¬
 to the same metadata and time at once. You need to select at least two photos.
- Open this script in SCript Editor and run it by pressing the "Run" button.
- The script will copy the date, the title, the description, the GPS coordinates, and the keywords ¬
 from the first image and set all photos to the same metadata. It will add a small time increment ¬
 to the time, so successive photos will remain sorted by time. This increment is determined ¬
 by the variable timeIncrement. Set it to zero, if you want the time copied exactly.

- The script will return the last date it changed

- if you save this script as an Application you can add it to the Dock 
  and run it from there

Note - for some photos it may not be possible to change the time, 
then running "Adjust date and time" for all photos once may help. 
Photos does not display the times with timezones,¬
so the results may look wrong, if the photos have been taken in different timezones.

This script has been tested in Photos version 9.0, with macOS X 14 Sequoia

© Léonie
*)

set timeIncrement to 0.02 -- the time increment in minutes; -- set this to "0", if you do not want an increment

(* select at least 2 images in Photos *)

tell application "Photos"
	activate
	set imageSel to (get selection)
	if (imageSel is {}) or (the length of imageSel < 2) then
		error "Please select at least two images."
	else
		
		set first_image to item 1 of imageSel
		
		set first_date to the date of first_image as date
		
		set firstKeywords to (the keywords of first_image) as list
		set hasKeywords to (firstKeywords is not equal to {missing value})
		
		
		set firstTitle to (the name of first_image) as string
		set hasTitle to (firstTitle is not equal to missing value)
		
		set firstDescription to the description of first_image
		set hasDescription to (firstDescription is not equal to missing value)
		
		
		set withAlti to false
		set withLati to false
		set withLongi to false
		
		
		try -- lift the GPS values
			set hasGPS to true
			tell the first item of imageSel
				set loc to get the location --retrieve longitude and latitude as list
				set alti to get the altitude -- retrieve the altitude
				
				set lati to (the first item of loc) -- as number
				set longi to (the second item of loc) -- as number
				
				set withAlti to (alti is not equal to missing value)
				set withLati to (lati is not equal to missing value)
				set withLongi to (longi is not equal to missing value)
				
				if not withLati then
					error "Photo has no Latitude assigned"
				end if
				
				if not withLongi then
					error "Photo has no Longitude assigned"
				end if
				if (lati > 90.0) or (lati < -90.0) then
					error "Latitude out of range " & lati
					
				end if
				if (longi > 180.0) or (longi < -180.0) then
					error "Longitude out of range " & longi
				end if
				
			end tell
		on error errTexttwo number errNumtwo
			set hasGPS to false
			
			display dialog "No GPS: " & errNumtwo & return & errTexttwo
		end try
		
		--	return {loc, alti, first_date, firstKeywords, firstTitle, firstDescription, hasKeywords} -- test
		
		repeat with i from 2 to count of imageSel
			
			set next_image to item i of imageSel
			
			set next_date to (the date of next_image) as date
			set time_difference to (first_date - next_date) ¬
				+ ((i - 1) * timeIncrement * minutes)
			--	return time_difference
			try
				tell next_image
					--stamp the time
					set the date of next_image to (next_date + time_difference) as date
					--stamp the GPS
					if hasGPS then
						set its location to {lati, longi}
					end if
					--stamp the title
					if hasTitle then
						set its name to firstTitle as string
					else
						set its name to its filename
					end if
					-- stamp the description
					if hasDescription then
						set its description to firstDescription
					end if
					-- stamp the keywords
					
					if hasKeywords then
						set its keywords to firstKeywords
					end if
				end tell
			on error errText number errNum
				display dialog "Error: " & errNum & return & errText & "Trying again"
				try
					delay 2
					tell next_image
						--stamp the time
						set the date of next_image to (next_date + time_difference) as date
						--stamp the GPS
						if hasGPS then
							set its location to {lati, longi}
						end if
						--stamp the title
						if hasTitle then
							set its name to firstTitle as string
						else
							set its name to its filename
						end if
						-- stamp the description
						if hasDescription then
							set its description to firstDescription
						end if
						-- stamp the keywords
						
						if hasKeywords then
							set its keywords to firstKeywords
						end if
					end tell
				on error errTexttwo number errNumtwo
					display dialog ¬
						¬
							"Skipping image due to repeated error: " & errNumtwo & return & errTexttwo
				end try -- try 2
			end try -- try 1
		end repeat
	end if	
    return "Adjusted the metadata of " & (the length of imageSel) ¬
		& " photos. The last date is " & ¬
		((the date of next_image) as date)
end tell


Dieses Dokument wurde anhand der folgenden Diskussion generiert: Skript: Kopieren aller Metadaten von einem Bild auf andere Bilder

Kommentare

29. Juli 2024 01:21

Liebe Leonie,


herzlichen Dank für das Teilen deines Scripts, wobei ich mich an Droplets erinnert fühle. Wissen zu Teilen regt immer das weitere Wissen an - ganz, ganz lieben Dank für dieses so nützliche Tool.


Liebe Grüße! 🌺

29. Juli 2024 01:21

29. Juli 2024 01:43

Liebe Leonie, ich habe noch zwei kleine Syntax-/Übertragungsfehler gesehen:

(* select at least 2 images in Photos *)tell application "Photos"

...

end if	return "Adjusted the metadata of " & (the length of imageSel) ¬


Korrigiert:

(* select at least 2 images in Photos *)
tell application "Photos"

...

end if
	return "Adjusted the metadata of " & (the length of imageSel) ¬


Liebe Grüße! 🌺

29. Juli 2024 01:43

29. Juli 2024 04:26

Ganz herzlichen Dank für das sorgfältige Korrekturlesen, PreCognition.

Ich habe es gleich korrigiert.

Das macht mich jetzt etwas besorgt, dass beim Kopieren aus dem Skript Editor, wo ich es getestet habe, wieder Zeilenumbrüche verloren gegangen sind.


Lieb Grüße

Leonie


29. Juli 2024 04:26

Willkommen in der Apple Support Community
Ein Forum, in dem Apple-Kunden sich gegenseitig mit ihren Produkten helfen. Melde dich mit deinem Apple Account an, um Mitglied zu werden.