Skip to content

Instantly share code, notes, and snippets.

@chris-kobrzak
Last active July 31, 2018 23:11
Show Gist options
  • Save chris-kobrzak/3313c50e7fabe89b826843666072b08d to your computer and use it in GitHub Desktop.
Save chris-kobrzak/3313c50e7fabe89b826843666072b08d to your computer and use it in GitHub Desktop.
Bulk resize images in directories preserving modification date timestamps
#!/usr/bin/env bash
for directory in */ ; do
dirTimestamp="$(GetFileInfo -d "$directory")"
(
cd "$directory"
# In this case img files have no extensions
for fileName in `find . -type f -maxdepth 1 ! -name "*.*"`; do
fileTimestamp="$(GetFileInfo -d "$fileName")"
sips --resampleWidth 800 "$fileName"
SetFile -m "$fileTimestamp" -d "$fileTimestamp" "$fileName"
done
)
SetFile -m "$dirTimestamp" -d "$dirTimestamp" "$directory"
echo "$directory $dirTimestamp"
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment