Script to automate setting dates in Photos from the file name
I recently imported a bunch of videos in the Photos for Mac app that had been previously imported from my MiniDV and AVCHD video cameras using iMovie over ten years ago. I just don't use iMovie enough to warrant keeping those videos walled off in a separate app so I decided to bring them into Photos.
Of course, importing these files set the date/time to the date and time they were imported. All of the imported videos had filenames that incorporated the actual date and time from their original metadata but apparently when imported into iMovie, that metadata wasn't preserved in a way the Photos could import.
Now, I could go through the 500+ videos and manually use the Adjust Date and Time… command but that seemed silly on a modern computer.
So, AppleScript and Github to the rescue. I'm not an AppleScript expert but I've used a number of other languages and I found some sample scripts on Github that had some pieces of what I was trying to do. So I cobbled together a script and am sharing it here in case others might find it useful.
Specifically, this script will go through a selection of items in Photos for Mac and try to set their date and times to match the date and time that in in the filename.
This seems to only be useful for videos imported through iMovie (maybe Final Cut, not sure) which use a specific file name format of "clip-YYYY-MM-DD HH;MM;SS.ext" If your videos don't match this format, then you'll have to modify this script or find a different one. It performs almost no validation on the compatibility of the file name to this format and I didn't bake in any error handling so, USE IT AT YOUR OWN RISK.
Anyway, here's the script: