iomonk (YoniCrisis)

1.5M ratings
277k ratings

See, that’s what the app is perfect for.

Sounds perfect Wahhhh, I don’t wanna

Script to read metadata and modify creation date in automator.

Will need to modify it to pass the date and use to change file names to reflect date photo was taken.

for f in “$@” do touch -t $(date -j -f “%Y%m%d%H%M” -v-6H $(mdls $f | grep kMDItemContentCreationDate | head -n1 | awk ’{gsub(“[^[:digit:]]+”,“ ”);print $1$2$3$4$5}’) +%Y%m%d%H%M) $f done

OK, found another of his videos and merged the ideas into this script In automator add run shell script and check the dropdown is at bin/zsh, not bash, and use as argument…

for f in “$@”
do
date_str=$(date -j -f “%Y%m%d%H%M” -v+3H $(mdls “$f” | grep kMDItemContentCreationDate | head -n1 | awk ’{gsub(“[^[:digit:]]+”,“ ”);print $1$2$3$4$5}’) +%Y%m%d%H%M)
filename=$f:t
filepath=$f:h
mv $filepath/{“$filename”,“$date_str $filename”
}
done


Thanks to this dude! Video 1

And video 2

Everything else down here is pretty much mumbo jumbo… ignore

So this gets me the clean content creation date from the file in terminal

prj_seca20230222-001.jpeg | grep kMDItemContentCreationDate | head -n1 | awk ’{gsub(“[^[:digit:]]+”,“ ”);print $1$2$3$4$5}’

The following will be just random notes for myself

if photo taken in Peru date -j -f “%Y%m%d%H%M” -v+3H
(00-05+08) reverse the Cupertino time to 00 and then to Perú time

$( to evaluate what is inside parenthesis )
+%Y%m%d%H%M to spit it out in that format

for f in “$@”
do
date_str=$(date -j -f “%Y%m%d%H%M” -v+3H $(mdls “$f” | grep kMDItemContentCreationDate | head -n1 | awk ’{gsub(“[^[:digit:]]+”,“ ”);print $1$2$3$4$5}’) +%Y%m%d%H%M)
echo “$date_str”
done

to rename

for f in “$@”;
do date_str=$(date -j -f “%Y%m%d%H%M” -v+3H “$(mdls ”$f" | grep kMDItemContentCreationDate | head -n1 | awk ’{gsub(“[^[:digit:]]+”,“ ”); print $1$2$3$4$5}’) “ +%Y%m%d%H%M)
extension=”${f##*.}“
mv ”$f" “${date_str}.${extension}”
done

This is an example of parameter expansion in Bash shell.

The ${f##*.} syntax removes the longest matching pattern of *. (i.e., any character followed by a dot) from the beginning of the value of $f, which is a filename string. This effectively strips off the filename prefix, leaving only the file extension.

For example, if $f is my_file.txt, then ${f##*.} would evaluate to txt.

So the line extension=“${f##*.}” assigns the file extension (if any) of the current file to the $extension variable.


To strip the extension and the last 3 characters from a filename, you can use parameter expansion with the ${var%pattern} syntax.

Here’s an example command that removes the file extension and the last 3 characters from the filename stored in the $filename variable:

newname=“${filename%.*}" 
newname=”${newname%???
}“

The first line removes the file extension (if any) from the filename by removing the shortest matching pattern of .* (i.e., a dot followed by any characters) from the end of the string.

The second line removes the last 3 characters from the filename by removing the shortest matching pattern of ??? (i.e., any 3 characters) from the end of the string.

After these two lines, the resulting $newname variable will contain the filename with the extension and last 3 characters removed.

2code automator Youtube