You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Script: Lift and Stamp all Metadata from one Photo to Other Photos -2018

by: 
Last modified: Jul 8, 2024 10:41 AM
4 2831 Last modified Jul 8, 2024 10:41 AM

Photos does not (yet) have the capability to lift all metadata from one photo and to stamp them onto other selected photos, like we can do in Aperture.

That makes it a tedious job to assign the metadata again, if we have to edit a photo externally in an editor, that is not supported by Photos and to reimport them.

But we can use AppleScript to read some of the metadata and copy them to other photos. AppleScript can access the title, the description, the keywords, the capture date and time, the GPS location. The altitude can be read, but not written.


The following Apple Script will lift the tags mentioned above from one photo and assign them to all other selected photos.

You can use it like this:

  • Create an album with the photos you want to tag with the same metadata as the first photo in the album
  • Make the source photo the first photo to this album.
  • Then select first the source photo for the metadata, hold down the shift key and select the last photo in the album.


Now open the script in the Script Editor and click run.

All selected photos will have the same title, description, keywords, capture date and time, GPS location.


I added a little tweak:

  • By default the time will be incremented by a second between successive photos, so they will keep the sort order, when sorted by time. You can disable this by setting the variable timeIncrement to zero.
  • And If the first selected photo does not have a title, the script will set the titles of the following photos to their filenames.


Try this first on a separate library for testing and make a backup of your main Photos Library before you try batch changes this way, better safe than sorry!


(The previous version of this user tip (from before the migration to the new ASC platform) is here: Script: Lift and Stamp all Metadata from … - Apple Community


-- ✄-✄-✄-✄-✄-✄-✄-✄ 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 3.0, with MacOS X 10.13

© 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

Comments

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.