Batch Change Title to Capture Date-Location-Description-Padded Sequential Number

by: 
Last modified: Jul 7, 2020 2:09 AM
3 759 Last modified Jul 7, 2020 2:09 AM

This is a variation of OT's script to batch change the title of selected photos to the following format:


EXIF Capture Date (System's Short Date)–Description–Padded Sequential Number

: https://discussions.apple.com/docs/DOC-8443


If we want to insert the name of the location as well, we can try to insert the "Moment" of a photo into the title, like this:

set thePlace to "" -- default,empty moment, if the moment cannot be retrieved			
			try
				set thisId to id of next_image
				tell application "Photos"
					set theMoments to the name of (moments whose id of media items contains thisId)
					set thePlace to "-" & (item 1 of theMoments)
				end tell
			end try
			spotlight next_image -- testing

The line "Spotlight" will display the currently processed image for testing. Comment it out, when using the script routinely.


When using the script in Photos 5 on Catalina, the photos have to be selected in a top level album.


The full changed code of the script:


-- batch change the title to the input, © léonie, version 1.0.1

set n_digits to 2 -- how many digits for the appended number
set defaultsuffix to "IMG"

set answer to display dialog "Select the number of digits for the appended numbers (0 .. 10).  Selecting '0' will suppress the leading zeros." buttons {"o.k"} default answer n_digits

set n_digits_text to the (text returned of answer)
set n_digits to n_digits_text as number

set answer to display dialog "Enter a suffix to append to the photos" buttons {"o.k"} default answer defaultsuffix
set suffix to the (text returned of answer)

tell application "Photos"
	
	activate
	set counter to 1
	set imageSel to (get selection) -- get selected images
	if imageSel is {} then
		error "Please select some images."
	else
		repeat with next_image in imageSel
			
			-- the counter with padded numbers
			set ntext to the counter as text
			repeat while (the length of ntext < n_digits) -- add leading zeros
				set ntext to "0" & ntext
			end repeat
			
			
			-- retrieve the date
			set capture_date to (the date of next_image)
			set short_capture_date_string to the short date string of capture_date
			
			-- set capture_time_string to the time string of capture_date
			
			-- retrieve the location as the moment name
			set thePlace to "" -- default,empty moment, if the moment cannot be retrieved			
			try
				set thisId to id of next_image
				tell application "Photos"
					set theMoments to the name of (moments whose id of media items contains thisId)
					set thePlace to "-" & (item 1 of theMoments)
				end tell
			end try
			spotlight next_image -- testing
			
			
			set new_title to short_capture_date_string & thePlace & "-" & suffix & "-" & ntext as text
			
			tell next_image
				set the name to new_title as text
				set counter to counter + 1
			end tell
		end repeat
		
		-- return new_title
	end if
end tell
return new_title

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