Although this question is already quite old I had a very similar problem: My OneDrive folder changed somehow all the creation-date timestamps of about 1000 photos I had.
I created a Script that tries to convert the time-stamp based on the file-name for the selected files in Photos. The Files that cannot be converted are written in some log-file on the desktop.
Maybe this helps someone in the future
(* Batch change the capture-date of the selected photos based on filename.
How to use this script:
- Select all photos you want to change the date timestamp of in Photos
- Open this script and run it by pressing the "Run" button in the toolbar.
- The script will read the filename from the selected images and tries to convert the filename to some date-time format
- 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
*)
(* select at least 1 image in Photos *)
set originalDelimiters to AppleScript's text item delimiters
tell application "Photos"
activate
set image_selection to (get selection)
set n_changed to 0
if (image_selection is {}) then
error "Please select at least one image."
else
repeat with i from 1 to count of image_selection
set flag to true
set image to item i of image_selection
set image_name to (the filename of image)
-- convert name to date
if (image_name starts with "PHOTO") then
-- Example filename: PHOTO-2015-09-13-22-34-35.jpg
--set AppleScript's text item delimiters to "-" and "."
set AppleScript's text item delimiters to {"-", "."}
--set name_elements to text items of image_name
set dateList to text items 2 thru 7 of image_name
set AppleScript's text item delimiters to originalDelimiters
set theYear to item 1 of dateList
set theMonth to item 2 of dateList
set theDay to item 3 of dateList
set theHour to item 4 of dateList
set theMinute to item 5 of dateList
set theSecond to item 6 of dateList
set theDate to createDate(theDay, theMonth, theYear, theHour, theMinute, theSecond) of me
else if (image_name starts with "Foto ") then
-- "Foto 23.06.13 02 35 59.jpg"
set AppleScript's text item delimiters to {" ", "."}
set dateList to text items 2 thru 7 of image_name
set AppleScript's text item delimiters to originalDelimiters
set theDay to item 1 of dateList
set theMonth to item 2 of dateList
set theYear to item 3 of dateList
set theHour to item 4 of dateList
set theMinute to item 5 of dateList
set theSecond to item 6 of dateList
set theDate to createDate(theDay, theMonth, theYear, theHour, theMinute, theSecond) of me
else if (my is_int(items 1 thru 8 of image_name as string)) then
--"20171101_165319642_iOS.jpg"
set theYear to items 1 thru 4 of image_name as string
set theMonth to items 5 thru 6 of image_name as string
set theDay to items 7 thru 8 of image_name as string
set theHour to "11"
set theMinute to "11"
set theSecond to "11"
set theDate to createDate(theDay, theMonth, theYear, theHour, theMinute, theSecond) of me
else
-- skip image
set flag to false
--display dialog "If name does not start with \"PHOTO\" is not implemented yet."
my WriteLog(image_name)
end if
if flag then
tell image
set the date of image to theDate
set n_changed to n_changed + 1
end tell
end if
end repeat
end if
return "Adjusted the dates of " & (n_changed as string) & " photos."
end tell
on createDate(theDay, theMonth, theYear, theHour, theMinute, theSecond)
set theDateString to (theDay & "/" & theMonth & "/" & theYear & " " & theHour & ":" & theMinute & ":" & theSecond) as string
--display dialog the theDateString
set theDate to date theDateString
return theDate
end createDate
on is_int(txt)
try
set int to txt as integer
return true
on error
return false
end try
end is_int
-- https://stackoverflow.com/a/3781066
on WriteLog(the_text)
set this_story to the_text
set this_file to (((path to desktop folder) as text) & "log_NonConvertedPhotoNames")
my write_to_file(this_story, this_file, true)
end WriteLog
on write_to_file(this_data, target_file, append_data) -- (string, file path as string, boolean)
try
set the target_file to the target_file as text
set the open_target_file to ¬
open for access file target_file with write permission
if append_data is false then ¬
set eof of the open_target_file to 0
write (this_data & return) to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file