Last active
May 24, 2022 11:07
-
-
Save gingerbeardman/5239df9d087df952bf7ed054ed35b10c to your computer and use it in GitHub Desktop.
Extract a zip and bake original sort order as Finder comments and last modified date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# by Matt Sephton @gingerbeardman | |
# dependencies: p7zip, pipx, osxmetadata | |
# $ brew install p7zip | |
# $ brew install pipx | |
# $ pipx install osxmetadata | |
# check your PATH and confirm operation | |
# get base of filename | |
BASE=$(basename "$1" .zip) | |
# get files in zip order, use 7z to respect character encodings | |
FILES=$(7z l -slt -ba "$1" | grep "Path" | sed 's/Path \= //g;') | |
# prepare timestamps | |
DATESTAMP=$(date -r "$1") | |
TOUCHSTAMP=$(date -jf "%a %b %d %T %Z %Y" "$DATESTAMP" +"%Y%m%d%H%M.%S") | |
# unzip and only show interesting lines of output | |
7z x "$1" -aoa -o"$BASE" | grep "[th]ing" | |
# set counters | |
COUNTER=1 | |
## loop through file list | |
echo "$FILES" | while read f | |
do | |
# show progress | |
echo "Baking order $COUNTER: $f" | |
# bake order | |
osxmetadata -s findercomment "$COUNTER" "$BASE/$f" # finder comment | |
touch -t $(echo "scale=2;$TOUCHSTAMP - $COUNTER/100" | bc -l) "$BASE/$f" # last modified | |
# inc counter | |
COUNTER=$((COUNTER+1)) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice one Matt!