Skip to content

Instantly share code, notes, and snippets.

@GwynethLlewelyn
Created November 19, 2022 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GwynethLlewelyn/619bb82bf2f9fecba4592c870760718a to your computer and use it in GitHub Desktop.
Save GwynethLlewelyn/619bb82bf2f9fecba4592c870760718a to your computer and use it in GitHub Desktop.
Shell script to change the modification date of a PSD file to the EXIF data within
# !/bin/sh
#
# date2exifdate shell script
# (tested on bash only)
# (c) 2022 by Gwyneth Llewelyn. Most rights reserved.
#
# Licensed under a MIT License (see https://gwyneth-llewelyn.mit-license.org/)
#
#
# Purpose: Change the modification date of a PSD file to the EXIF data within
#
# Rationale: Some stupid cloud storage systems (either on local NAS or remote servers...),
# when restoring files to a local directory, sometimes 'forget' the original date, and,
# instead, just place the date of the full sync. This is annoying since previously all files
# would be (correctly) sorted by modification date... and all that information will be lost.
#
# A partial solution is to read the original modification date from the EXIF or XMP headers and change
# the Unix modification date to be the same. This is particularly easy to do on PSD files (even ancient
# versions of Photoshop would properly tag everything with EXIF tags), but quite hard on other formats,
# especially when they're meant to be used on the Web, where shaving off a few extra bytes is so crucial.
#
# In my use-case, I tend to have a 'master' PSD file, and a series of images, in different formats and sizes,
# with pretty much the same name as the 'master' PSD file. The series of commands below will not only change
# the PSD but also all files that have the same common basename.
#
# Obviously none of the rest will be changed, and this script isn't recursive, either. Caveat utilitor!
#
# Preconditions: exiftool needs to be installed
# On Debian/Ubuntu this is trivial to install
# On other platforms, make sure you do have Perl installed; a correctly-configured CPAN
# will also do wonders to deal with dependency packages :-)
# The code below is very wordy and chatty; feel free to get rid of all unnecessary debugging information
# for a cleaner output
let i=0;
for f in *.psd;
do
echo $i:"$f(unstripped)";
fstripped=$(basename -s .psd "$f");
originalDate=$(exiftool -p '${ModifyDate#;DateFmt("%Y%m%d%H%M.%S")}' "$fstripped".psd);
echo $originalDate;
touch -t $originalDate "$fstripped".*;
ls -l "$fstripped".*;
let i=$i+1;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment