Skip to content

Instantly share code, notes, and snippets.

@giuliobosco
Last active March 2, 2022 06:51
Show Gist options
  • Save giuliobosco/908530e37e27cb56fd91a6e183c1812e to your computer and use it in GitHub Desktop.
Save giuliobosco/908530e37e27cb56fd91a6e183c1812e to your computer and use it in GitHub Desktop.
macOS rename photos in folder for with photo shooting date
#!/bin/bash
for filename in $(pwd)/*; do
line=$(mdls $filename | grep kMDItemFSCreationDate)
fileExtension=$(echo $filename | cut -f2 -d".")
datetime=$(echo $line | cut -f2 -d "=")
date=$(echo $datetime | cut -f1 -d " ")
time=$(echo $datetime | cut -f2 -d " ")
time=$(echo $time| sed -r 's/[:]+//g')
mv $filename $date-$time.$fileExtension
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment