1

Hi i have a problem renaming a lot of photo and images files. I use a shellscript in automator to rename them by EXIF date and time. But the time is given by UTC and im living in europe with +0100 in vinter and +0200 in the summer.

Example: a picture from 2020-06-30 taken at 22:22:30
is named "2020-06-30 20/22/30 IMG_0001.jpg"
instead of. "2020-06-30 22/22/30 IMG_0001.jpg"

im using the script:

#/bin/zsh
for f in "$@"
do
    filedate=$(mdls $f | grep kMDItemContentCreationDate -m 1 | awk '{print $3, $4}');
    filename=$f:t
    filepath=$f:h
    mv $filepath/{"$filename","$filedate $filename"}
done

Can i somehow just add +0200 or +0100 to the "filedate...$4" and how?(and then manually order when the number of houser in the name is over 24) or is there a smarter way to ad time zone designator(TZD) to the script? I have not used script before so im completely new to all this. Hopw someone can help me.

  • Just a 'by the way'… your time format 20/22/30 will cause huge problems for Windows users if they ever get the file You should use something platform agnostic, like 20.22.30 or 20-22-30 See stackoverflow.com/questions/1976007/… for characters you should avoid in filenames. – Tetsujin Jul 10 at 7:43
  • 1
    thanks for the hint, actually im deleteting the "/" with another automator action so it just "2020-06-30 202230 IMG_0001.jpg" for the same reason. – Claus Dragonmonkey Olsen Jul 10 at 10:10
0

To change UTC time to reflect your timezone, run the output of mdls thru the date command. You can also format the output of the date command.

utcfiledate=$( mdls -n kMDItemContentCreationDate -raw  FILE)

date -f '%F %T %z' -j "$utcfiledate" '+%F %T'

To remove the colons from the output

date -f '%F %T %z' -j "$utcfiledate" '+%F %H%M%S'
| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .