Change file creation and modification dates based on file name?

I have captured all my home movies from DV tapes and would like to set the creation and modification dates to the original date the footage was recorded. I want the footage to sort correctly in Apple Photos. Thankfully Final Cut Pro named all the footage with the correct date and time.

Tape name - yyyy-mm-dd hh/mm/ss

Footage 009 - 2004-10-24 08/04/55-1.mov
Footage 009 - 2004-10-24 17/29/07.mov
Footage 009 - 2004-10-29 19/05/54.mov
Footage 010 - 2004-11-23 11/29/36.mov
Footage 010 - 2004-11-23 12/22/55.mov
Footage 010 - 2004-11-27 10/56/45.mov

I am hoping to do this via an Automator App or Service so I can drop the files on the app or select them and right click to change the files.

I have found a few similar questions online, but I am not sure how to modify some of the solutions to work with my file name format. Any help would be appreciated!

https://macscripter.net/viewtopic.php?pid=138881#p138881
https://discussions.apple.com/thread/250940404

Model: iMac 21.5"
Operating System: macOS 10.13

chadsgreene. This is a basic script that should do what you want. I’ve only tested it with a few files, but it seems to work as desired. The script builds on Shane’s script in the Macscripter thread linked in your post.

To test this script, save it as an app on your desktop and drag a few of the MOV files onto the app. It’s important that these files are copies and not originals. If a file without the required date and time information is dragged onto the app, the app simply ignores that file.

The script changes forward slashes into colons, and I wasn’t sure how to handle this. Perhaps another forum member will be able to advise on this matter. The script seems to work, so perhaps it’s OK as written in this regard.

use framework "Foundation"
use scripting additions

on open theDroppedItems
	repeat with aFile in theDroppedItems
		set theDateAndTime to getDateAndTime(aFile)
		if theDateAndTime ≠ "No date and time" then setDateAndTime(aFile, theDateAndTime)
	end repeat
end open

on getDateAndTime(theFile)
	set theText to (current application's NSString's stringWithString:(POSIX path of theFile))
	set regExPattern to "\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}"
	set theRange to theText's rangeOfString:regExPattern options:(current application's NSRegularExpressionSearch)
	if |length| of theRange = 0 then return "No date and time"
	return (theText's substringWithRange:theRange)
end getDateAndTime

on setDateAndTime(theFile, theDateAndTime)
	set theFile to (current application's |NSURL|'s fileURLWithPath:(POSIX path of theFile))
	set df to current application's NSDateFormatter's new()
	(df's setDateFormat:"yyyy-MM-dd' 'HH:mm:ss")
	set theDateAndTime to (df's dateFromString:theDateAndTime)
	(theFile's setResourceValue:theDateAndTime forKey:(current application's NSURLCreationDateKey) |error|:(reference))
	(theFile's setResourceValue:theDateAndTime forKey:(current application's NSURLContentModificationDateKey) |error|:(reference))
end setDateAndTime

peavine this totally changed the modified and creation dates! Unfortunately when I imported the changed movie into Apple Photos it did not sort correctly and still showed the Dec 3, 2021 capture date. There must be a different date. Maybe the Exif date?

chadsgreene. I looked at the Photos dictionary and the Media Item class has a date property. Perhaps it sorts on that. I don’t use the Photos app and can’t help with that.

I did some more research and found the I need to change the “Quicktime Create Date”. Do you know how to change that with your script?

The Photos.app has view sorted with Imported On date. It has nothing to do with the date of creation or modification. And you can’t force Photos.app to sort or display the media items list any other way.

The “Quicktime Create Date” metadata is most easily modified with the free utility named exiftool. Only, this change will not affect the Photos.app interface in any way.

Therefore, it is better to try changing the Imported On by editing the date property of the media item. Which is what @peavine hinted at.

I did some more tests and found that changing the Quicktime Create Date caused Photos.app to sort the video properly. A Better Finder Attributes’ trial let me change the date based on the name. It is a $20 program, so at this point it is probably easiest to purchase the program.
https://www.publicspace.net/ABetterFinderAttributes/index.html

Thank you all for your help and time, especially you peavine. We got so close!