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.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to change a photo TITLE to date captured in YYYYMMDD-HHMM format in Photos v8.0 running Ventura?

I have a 2021 MacBook Pro running Ventura 13.0.1. I have the Photos app for my photos. Before Ventura, I was running a script that allowed me to change the title of my photos to YYYYMMDD-HHMM.


Since Ventura, there is no longer the option to change the date and time settings to this format.


There is only System Settings>General>Language & Region and the options of 2023-08-20, 2023/08/20 or 2023.08.20. Other people want this format also and have tried all other Regions but none work.


I am thinking the script I was using could be modified to reflect the YYYYMMDD-HHMM format and not use the Mac system settings. Or possibly a completely new script. I know nothing about how to modify or create a script. Only how to use them.


The script I'm using is from Léonie, shared by Old Toad. Any help would be greatly appreciated!!

MacBook Pro (2021)

Posted on Aug 21, 2023 9:33 AM

Reply
Question marked as Top-ranking reply

Posted on Aug 24, 2023 8:00 AM

Here you go. Example of script result for a selected image in Photos on macOS Ventura 13.5.1:



Launch Apple's Script Editor and paste the following code into it. Do not copy the literal word Code though. Press the hammer icon to compile it into multi-colored code. Select an image in Photos and press cmd+i to open its Get Info panel. In Script Editor, click ▷ (run) and watch the Get Info Title change to the above format.


Code


-- get the selected photos date field which is also the EXIF
-- DateTimeOriginal stamp, and convert that string to another
-- format (e.g. YYYYMMDD-HHMM).

use scripting additions

tell application "Photos"
	set imageSel to (get selection)
	repeat with i from 1 to count of imageSel
		set next_image to item i of imageSel
		set dto to next_image's date as date
		tell next_image
			set its name to my dateFormatter(dto)
		end tell
	end repeat
end tell

return

on dateFormatter(dstr)
	-- create new date string YYYYMMDD HHMM from iPhoto image's date
	set {year:y, month:m, day:d} to dstr
	set timeslice to words of time string of dstr
	set hourT to leftpadzero(first item of timeslice)
	set minT to my leftpadzero(second item of timeslice)
	-- month is a name string and becomes an integer 1-12 with casting)
	set monT to my leftpadzero(m as integer)
	set dayT to my leftpadzero(d)
	return (y & monT & dayT & "-" & hourT & minT) as text
end dateFormatter

on leftpadzero(val)
	-- left pad single-digits with 0
	set padstr to ""
	set padstr to text -2 thru -1 of ("00" & val)
	return padstr as text
end leftpadzero


Similar questions

12 replies
Question marked as Top-ranking reply

Aug 24, 2023 8:00 AM in response to VikingOSX

Here you go. Example of script result for a selected image in Photos on macOS Ventura 13.5.1:



Launch Apple's Script Editor and paste the following code into it. Do not copy the literal word Code though. Press the hammer icon to compile it into multi-colored code. Select an image in Photos and press cmd+i to open its Get Info panel. In Script Editor, click ▷ (run) and watch the Get Info Title change to the above format.


Code


-- get the selected photos date field which is also the EXIF
-- DateTimeOriginal stamp, and convert that string to another
-- format (e.g. YYYYMMDD-HHMM).

use scripting additions

tell application "Photos"
	set imageSel to (get selection)
	repeat with i from 1 to count of imageSel
		set next_image to item i of imageSel
		set dto to next_image's date as date
		tell next_image
			set its name to my dateFormatter(dto)
		end tell
	end repeat
end tell

return

on dateFormatter(dstr)
	-- create new date string YYYYMMDD HHMM from iPhoto image's date
	set {year:y, month:m, day:d} to dstr
	set timeslice to words of time string of dstr
	set hourT to leftpadzero(first item of timeslice)
	set minT to my leftpadzero(second item of timeslice)
	-- month is a name string and becomes an integer 1-12 with casting)
	set monT to my leftpadzero(m as integer)
	set dayT to my leftpadzero(d)
	return (y & monT & dayT & "-" & hourT & minT) as text
end dateFormatter

on leftpadzero(val)
	-- left pad single-digits with 0
	set padstr to ""
	set padstr to text -2 thru -1 of ("00" & val)
	return padstr as text
end leftpadzero


Aug 21, 2023 2:07 PM in response to deege

Yes, they dropped that option of formatting the date as you would prefer. Tell Apple what missing features you'd like restored via Feedback - macOS - Apple.  


I vaguely recall a post where the format could be done in the script but that was some time ago and my memory ain't what it used to be. This topic may have something you can use: Convert current date to YYYYMMDDHHMMSS fo… - Apple Community

Aug 21, 2023 11:37 AM in response to deege

I ran this script, "Batch Changing the Title to the Capture Date & Time",


(* Batch change the titles of the selected photos to the capture time


How to use this script:

- Select all photos you want to change the title of in Photos

- Open this script and run it by pressing the "Run" button in the toolbar.

- The script will read the capture date from the selected images and create a short date string according to the system preferences for the short date format in System Preferences > Language & Region > Advanced


- The script will return the last date of the last photo it changed


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


This script has been tested in Photos version 1.0, with MacOS X 10.10.3

© Léonie

*)

(* select at least 1 image in Photos *)

tell application "Photos"

activate

set imageSel to (get selection)

if (imageSel is {}) then

error "Please select at least one image."

else

repeat with i from 1 to count of imageSel

set next_image to item i of imageSel

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

set new_title to short_capture_date_string & " @" & capture_time_string

tell next_image

set the name of next_image to the new_title as text

end tell

end repeat

end if

return "Adjusted the titles of " & (the length of imageSel) & " photos. The last date is " & ((the date of next_image) as date)

end tell


on some photos in a Ventura library with these results:


NOTE: I compiled the script as an application and had to give it Full Disk Access in System Settings for it to work.


The format is not what you posted but I assume you modified the script for that format.



Aug 21, 2023 2:15 PM in response to deege

As the code here is in AppleScript, I will submit how one converts the selected photo's date (really its EXIF DateTimeOriginal stamp) to a custom formatted YYYYMMDD-HHMM string.


-- get the selected photos date field which is also the EXIF
-- DateTimeOriginal stamp, and convert that string to another
-- format (e.g. YYYYMMDD-HHMM).

use scripting additions

tell application "Photos"
	set imageSel to (get selection)
	repeat with i from 1 to count of imageSel
		set next_image to item i of imageSel
		set dto to next_image's date as date
	end repeat
end tell

set newDateStr to my dateFormatter(dto) as text
display dialog "Custom Date String from Photo's EXIF date:" & return & return & newDateStr ¬
	with title "Photo's Date String"
return

on dateFormatter(dstr)
	-- create new date string YYYYMMDD HHMM from iPhoto image's date
	set {year:y, month:m, day:d} to dstr
	set timeslice to words of time string of dstr
	set hourT to leftpadzero(first item of timeslice)
	set minT to my leftpadzero(second item of timeslice)
	-- month is a name string and becomes an integer 1-12 with casting)
	set monT to my leftpadzero(m as integer)
	set dayT to my leftpadzero(d)
	return (y & monT & dayT & "-" & hourT & minT) as text
end dateFormatter

on leftpadzero(val)
	-- left pad single-digits with 0
	set padstr to ""
	set padstr to text -2 thru -1 of ("00" & val)
	return padstr as text
end leftpadzero


The image I selected in Photos was taken on July 26, 2010 at 1:02:14 pm. The display dialog above shows:



and I left pad single day, month, hour and minute times with zeroes to keep the formatting consistent.


In the UNIX world the following would do both handler's job and return the correct string where the literal date below is replaced by the Photo's date value. The syntax to do this in AppleScript is horrendous due to one needing to escape double-quotes.


date -j -f "%A, %B %e, %Y at %l:%M:%S %p" "Monday, July 26, 2010 at 1:02:14 PM" "+%Y%m%d-%I%M"
20100726-0102


The percent codes are known as strftime codes and documented either in the Terminal as strftime(3) man page, or at the OpenGroup's strftime page.

Aug 21, 2023 12:58 PM in response to Old Toad

Thank you for your reply Old Toad! This is the script I already have. Although I use a dash instead of an ampersand.


However, I should have clarified that before Ventura, you could go into system settings date and time and make it ANY format that you want. Now there are only the options for those I listed above (and a couple more that don't work for me).


Your statement: "The format is not what you posted but I assume you modified the script for that format." is what I was referring to.


I don't know how to modify the script for the format I'm needing. Is there a way to do that? Or can this script only use the system settings date and time formats in the Ventura system settings?

Aug 22, 2023 7:37 AM in response to deege

The purpose of my script was to show how to manufacture the expected YYYYMMDD-HHMM string from the next_image's date and then display it as proof, not actually set the selected image's name (title). So yes, clicking the OK on that dialog ends the script.


Let's say I have an image in Photos whose filename is 503A0823.CR3, and its DateTimeOriginal (its date) is December, 26, 2022 at 4:13:03 PM. Do you want the name (title) of the selected image in Photos to be set to the following format?


20221226-0413


If this is the case, I have working code derived from what Old Toad previously offered but using my two handlers.

Aug 22, 2023 5:55 PM in response to VikingOSX

Yes!! That is exactly what I am wanting! I'm afraid I don't know very much about all this. I don't know what "handlers" are. I have never manipulated a script except to add a name at the end. Is what you posted above something that needs to be changed? Or a completely new script?

Thank you again so much!!

Aug 24, 2023 7:46 AM in response to deege

Its 2023-08-24 10:40 and the power is out thanks to some storms. I am typing this from the public library.


There is enough code posted in the current threads that I can reconstruct a solution that uses some of my code to get you a selected Photos image titled with its date information as YYYYMMDD-HHMM string. Need a few minutes to build and test it here.


In AppleScript terms, handlers are the same as functions or subroutines and these are donated with the on clause where one passes data to them and they return a result.

How to change a photo TITLE to date captured in YYYYMMDD-HHMM format in Photos v8.0 running Ventura?

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