Last active
April 2, 2020 13:54
-
-
Save darwin/f346a5c5d0e3d58d7129e46d62261732 to your computer and use it in GitHub Desktop.
This scripts finds all files in given directory tree, reads their com.apple.metadata:kMDItemDownloadedDate xattr and changes last modification date to that value if exists.
This file contains 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
#!/usr/bin/env bash | |
set -e | |
set_date_attr() { | |
local hex | |
hex=$(xattr -px "com.apple.metadata:kMDItemDownloadedDate" "$1") | |
if [[ $? = 0 ]]; then | |
local date_xml | |
date_xml=$(xxd -r -p <<< "$hex" | plutil -extract 0 xml1 -o - - | sed '4q;d' | sed -e 's/<[^>]*>//g') | |
echo -n "file '$1' has kMDItemDownloadedDate $date_xml" | |
local date_touch | |
date_touch=$(date -jf "%Y-%m-%dT%H:%M:%SZ" "$date_xml" "+%Y%m%d%H%M.%S") | |
echo " > touch -t \"$date_touch\" \"$1\"" | |
touch -t "$date_touch" "$1" | |
else | |
echo "file '$1' does not have kMDItemDownloadedDate xattr" | |
fi | |
} | |
export -f set_date_attr | |
cd "$1" | |
find . -type f | xargs -I {} bash -c 'set_date_attr "{}"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment