Batch write on attribute to another? #96
-
Dear RhetTbull, first of all: THANK you for the this little but REALLY GENIUS piece of software!!! :))) I recovered thousands of photos which - after recovery - were set with new Happily I could find with your tool the original I am really a noob in writing batch codes but maybe there could be a way to write out one value to a variable and write it back then to another? It would take me weeks to check each file and write the date manually .... :o Any help would be really appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi @KayGundhardt I believe this script will do what you want: #!/bin/sh
# Change the kMDItemFSCreationDate to kMDItemContentCreationDate for files using osxmetadata
# See: https://github.com/RhetTbull/osxmetadata/discussions/96
for arg in $@; do
new_date=$(osxmetadata --get kMDItemContentCreationDate $arg| cut -d"=" -f2 | tr -d ' ')
echo "Setting kMDItemFSCreationDate for $arg to $new_date"
osxmetadata --set kMDItemFSCreationDate $new_date $arg
done Save it to a file "change_date.sh" (or extract from attached zip) then in terminal do this: chmod u+x change_date.sh
./change_date.sh file.jpg You can pass a wildcard: ./change_date.sh *.jpg However, depending on what you really are trying to do, exiftool might be a better option. For example, this command changes the file system date to match the data the image was created from the image's metadata:
I recommend you test either one of these on a couple of files before modifying all your files! |
Beta Was this translation helpful? Give feedback.
-
Hi! W Thank you for the extra fast reply and super detailed answer! Actually it worked now with both: your (second) script and exiftools. Again: thXXXXXX-with-an-extra-X :) My purpose: I am regularly trying to keep all my photos (over 20 years) in order and already tried a bunch of different apps to do so (iPhoto, Photos, Lightroom (now Classic), and many more). Doing this I sadly hat to make the experience that no app at all will ever stay as it was over such a long period of time. I mean they change library structure massively or get more and more „cloudy“ or even both. To make a really loooooong story short: I decided to focus on simple file system structure using its directories via built in Finder app and - here it comes - mostly in column view. Now in this view finder does not show EXIF data and only FS creation date… So when I am sorting hundreds of pics, actually reviewing 2022 now, I need to orientate myself to FS creation date. Now as I recovered files from a crashed cams SD-card the FS creation date was set to recovery date, but - as described earlier - Content Creation date remained original… Hope this explains a bit what I was trying to accomplish… :) Kay |
Beta Was this translation helpful? Give feedback.
@KayGundhardt I realized that this solution won't actually work because it seems that kMDItemFSCreationDate cannot be set. osxmetadata appears to do it without error but the value doesn't get changed. There is a utility shipped with Apple developer tools called SetFile that can do this but I'm not aware of anything else that can change the actual creation date.
Also, I realized after I posted my answer that osxmetadat already includes a
--mirror
option that causes one attribute to mirror another so in your case, you could use:osxmetadata --mirror kMDItemFSCreationDate kMDItemContentCreationDate file.jpg
Except that as noted above this won't actually change kMDItemFSCreationDate.
Here's a…