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.

Script: Batch Change the Date and Time to a Fixed Date

by: 
Last modified: Dec 23, 2018 3:51 AM
12 33521 Last modified Dec 23, 2018 3:51 AM

This version of the script is no longer maintained, because the old code cannot be edited in the new version of the AppleSupport Communities platform.

Please use the new version of this user tip here: Script: Batch Change the Date and Time to a Fixed Date


------ obsolete --- ignore

iPhoto had the very convenient Batch Change tool to set the date and time of all selected photos to a fixed date, with a time increment added between successive photos. This was very convenient for older photos, that had no capture date embedded. This batch change option is missing in Photos. Here is a little Apple Script, that can be run to batch change the dates like in iPhoto. If you still have iPhoto installed, simply use iPhoto to batch change dates.


If your Photos Library is large or you are syncing your library with iCloud Photo Library, scroll down to version 2 of this script. It will be more robust.

To copy and paste it: (* Batch change the time of selected photos all at once
How to use this script: - Collect all photos you want to set to the same time in an album and sort them manually - Adjust the time of the first of your batch of photos with "Adjust Date and time" in Photos from the "Image" menu, even if the time is correct - Select first the photo with the adjusted date, the hold down the Shift key and select all photos you want to set to the same date and time at once. You need to select at least two photos. - Open this script and run it by pressing the "Run" button. - The script will copy the date from the first image and set all photos to the same date, and step the date by adding the increment given by the variable timeIncrement. - The script will return the last date it changed
- if you save this script as an Application you can add it to the Dock and run it from there
Note - for some photos it may not be possible to change the time, then running "Adjust date and time" for all photos once may help. Photos has a bug that displays timezones incorrectly, so the results may look wrong, if the photos have been taken in different timezones.
This script has been tested in Photos version 1.0, with MacOS X 10.10.3
© Léonie *)
set timeIncrement to 1 -- the time increment in minutes (* select at least 2 images in Photos *) tell application "Photos" activate set imageSel to (get selection) if (imageSel is {}) or (the length of imageSel < 2) then error "Please select at least two images." else
set first_image to item 1 of imageSel set first_date to (the date of first_image) as date repeat with i from 2 to count of imageSel
set next_image to itemi of imageSel set next_date to (the date of next_image) as date
set time_difference to (first_date - next_date) + ((i - 1) * timeIncrement * minutes)
tell next_image set the date of next_image to (next_date + time_difference) as date end tell

end repeat end if return "Adjusted the date and time of " & (the length of imageSel) & " photos. The last date is " & ((the date of next_image) as date) end tellVersion 2 - pass photos in an album:

The version above lets you select the photos to be batch changed directly in the All Photos album, but the "get selection" command is not very reliable in Photos. If your Photos library is large or you are using iCloud Photo Library the script above may give timeout errors.If that should be the case, this second version might work better. Only it requires, that you collect all photos to be processed in a fixed album, defined at the top level of the Photos Library. I tested this version on my iCloud Photo Library, that has 37000 photos, and so far it worked.And you have to define the name of this album in the script as a constant. This fix has been suggested by NicFletcher - his sample script uses this method:https://discussions.apple.com/thread/6999613?answerId=28087786022#28087786022


(* Batch change the time of selected photos all at once

How to use this script:- Collect all photos you want to set to the same time in an album and sort them manually to the sequence you want.- The album needs to be a toplevel album, not an album inside a folder.- Adjust the time of the first of your batch of photos with "Adjust Date and time" in Photos from the "Image" menu, even if the time is correct. to ensure it has an EXIF capture date.- Open this script and run it by pressing the "Run" button.- The script will copy the date from the first image and set all photos to the same date, and step the date by adding the increment given by the variable timeIncrement.- The script will return the last date it changed

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

Note - for some photos it may not be possible to change the time, then running "Adjust date and time" for all photos once may help. Photos has a bug that displays timezones incorrectly, so the results may look wrong, if the photos have been taken in different timezones.- Enter the name of your album in the first line of the script instead of "PhotoDropBox"

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

© Léonie*)

set theAlbumName to "PhotoDropBox" -- the photos will be passed in a toplevel album named "PhotoDropBox"

set timeIncrement to 1 -- the time increment in minutes

set imageSel to {}

tell application "Photos"

activate

try

if existscontainertheAlbumName then

set thePhotosBuffer to containertheAlbumName set imageSel to every media item of thePhotosBuffer else error "Album " & theAlbumName & "does not exist" end if

on error errTexttwonumbererrNumtwo display dialog "Cannot open album: " & errNumtwo & return & errTexttwo end try


if (the length of imageSel < 2) then error "Please select at least two images." else

set first_image to item 1 of imageSel try

tell first_image set first_date to its date end tell on error errText number errNum display dialog "Error: " & errNum & return & errText & "Trying again" try delay 2 tell first_image set first_date to its date end tell on error errTexttwonumbererrNumtwo error "cannot get the date of the first image" end try end try

-- set first_date to (the date of first_image) as date

repeat with i from 2 to count of imageSel

set next_image to itemi of imageSel try tell next_image set its date to first_date + ((i - 1) * timeIncrement * minutes) end tell on error errText number errNum display dialog "Error: " & errNum & return & errText & "Trying again" try delay 2 tell next_image set its date to first_date + ((i - 1) * timeIncrement * minutes) end tell on error errTexttwonumbererrNumtwo display dialog "Skipping image due to repeated error: " & errNumtwo & return & errTexttwo end try end try end repeat end if return "Adjusted the date and time of " & (the length of imageSel) & " photos. The last date is " & ((the date of next_image) as date)end tell

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