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.

Script requested for changing dates

<unnecessary background>

Photos has an awkward bug to import all videos in today's date. The "excuse" is that the date does not exist in the file metadata in videos. However, it appears in the File data (visible in Finder in the List view and easily editable in many third party apps). So all users know when their video was shot or modified, until they... make the mistake to entrust it to the library of the Photos App!

</unnecessary background>


Using a third party app, I have easily batch renamed all my photos and videos in the following name format (and I urge users to do the same):


YYYY-MM-DD-HH-MM - ParentFolderName - OriginalFilename.jpg

(the first part is the date and time the file was created)


The videos have been imported in Photos App using these long filenames above.


I need a script that for a given selection of pictures or videos in the Photos library, it will be copying the date and time from the first part of the filename and then pasting it to the actual date and time of each picture/video (field-by-field).


The script can be based on the known script of Leonie: Script: Batch Change the Date and Time to a Fixed Date.


The script will provide a workaround which will finally solve this very troubling date issue for many Photos users.



MacBook Pro 16", macOS 10.15

Posted on Mar 26, 2020 6:28 PM

Reply
Question marked as Top-ranking reply

Posted on Mar 28, 2020 4:16 AM

I hired an AppleScript expert via Upwork.com and he created the script for me!

His name is Michele Percich and I highly recommend him for any relevant work you may have!

I am hereby releasing the script for public usage by anyone interested.

It is a perfect workaround for fixing the dates of your imported videos in Photos App.


Script and instructions follow:


-- Script to change date and time from filename 

--

-- Usage: select pictures/videos in Photo, then launch the script

-- Filenames must start with the desired date in the following format: 

-- YYYY-MM-DD-hh-mm

-- You must rename your images or videos BEFORE importing them to Photos App.

-- You can use a batch renamer from the web to do that, such as Renamer.com 

-- Make sure the date format is correct as above.

-- The script will change the date and time tag in Photos app according to the filename!

--



tell application "Photos"

	activate

	set theseItems to (get the selection)

	repeat with thisItem in theseItems

		set theFilename to filename of thisItem

		set theDate to text 1 thru 16 of theFilename

		set aDate to current date

		tell aDate to set {its year, its month, its day, its hours, its minutes, its seconds} to (words of (theDate & ":07"))

		set date of thisItem to aDate

	end repeat

end tell


Similar questions

3 replies
Question marked as Top-ranking reply

Mar 28, 2020 4:16 AM in response to NikoSilver

I hired an AppleScript expert via Upwork.com and he created the script for me!

His name is Michele Percich and I highly recommend him for any relevant work you may have!

I am hereby releasing the script for public usage by anyone interested.

It is a perfect workaround for fixing the dates of your imported videos in Photos App.


Script and instructions follow:


-- Script to change date and time from filename 

--

-- Usage: select pictures/videos in Photo, then launch the script

-- Filenames must start with the desired date in the following format: 

-- YYYY-MM-DD-hh-mm

-- You must rename your images or videos BEFORE importing them to Photos App.

-- You can use a batch renamer from the web to do that, such as Renamer.com 

-- Make sure the date format is correct as above.

-- The script will change the date and time tag in Photos app according to the filename!

--



tell application "Photos"

	activate

	set theseItems to (get the selection)

	repeat with thisItem in theseItems

		set theFilename to filename of thisItem

		set theDate to text 1 thru 16 of theFilename

		set aDate to current date

		tell aDate to set {its year, its month, its day, its hours, its minutes, its seconds} to (words of (theDate & ":07"))

		set date of thisItem to aDate

	end repeat

end tell


Apr 6, 2020 2:06 PM in response to NikoSilver

I have found the full workaround to the date issue for all files!

Briefly, you do 3 steps:

  1. You download and install ExifTool (free) to change the file creation dates and file modification dates to the exif (metadata) "Date/Time Original". The command for Terminal window is:


exiftool "-FileCreateDate<DateTimeOriginal" "-FileModifyDate<DateTimeOriginal" -r

...and then you drag and drop the directory tree where the pictures you want to modify are...

....YOU DOUBLE CHECK BECAUSE IT IS UNDOABLE FOR ALL SUBFOLDERS!!!...

...and you hit [enter]!


2. You use Renamer (.com - works for 15 days without subscription, then ~$10 or something) to batch rename all of them to "YYYY-MM-DD-hh-mm-ss old filename.ext". It's a simple app - you will learn how in 2 minutes.


3. You import them to Photos app and you apply my script


DONE!


ps. If you have already imported them, then you have a problem! Even if you delete them, Photos app remembers their previous filename! Try to wipe them well and wait for your Photos database to be updated. Maybe it will work.

Script requested for changing dates

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