Skript: Kopieren aller Metadaten von einem Bild auf andere Bilder

von: 
Zuletzt geändert: 08. Okt. 2017 13:45
4 580 Zuletzt geändert 08. Okt. 2017 13:45

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 restaurier,en 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 below this line to the end ✄-✄-✄-✄-✄-✄-✄-✄-✄-✄

(* 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 has a bug that displays timezones incorrectly, so the results may look wrong, if the photos have been taken in different timezones.


This script has been tested in Photos version 3.0, with MacOS X 10.13


© Léonie

*)


settimeIncrement 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_imagetoitem 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 descriptionoffirst_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 errTexttwonumbererrNumtwo

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_imagetoitemiofimageSel


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

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

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

-- ✄-✄-✄-✄-✄-✄-✄-✄-✄-✄. snip : copy until here ✄-✄-✄-✄-✄-✄-✄-✄-✄-✄---

A copy of this script is in my DropBox: https://www.dropbox.com/s/r9oersq22tyqaw4/PhotosLiftAndStampAllMetadata.scpt.zip ?dl=0


The script has been tested on Photos 3.0 on macOS 10.13 High Sierra


This user tip was generated from the following discussion: Lift and Stamp all Metadata from one Photo to Other Photos


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

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