I'm not keen on Apple's format either, and disappointed that they've not provided a method for users to customize that. I started noodling on this about a year ago, but something came up, and it went into the unfinished projects folder - now quite a large folder :) Anyway, I pulled it out, and solved the date conversion problem that had stumped me last year. Here it is:
A zsh
script for bulk-renaming Apple screenshots:
#!/bin/zsh
# shotfnmv.sh
cd $HOME/TestShots
for afile in *.png
do
echo $afile
oldfile=$(basename "$afile")
echo $oldfile
if [[ $oldfile == *"Screen Shot"* ]]; then
echo "Found an Apple-formatted Screen Shot file."
oldtimestr=$(echo "$oldfile" | awk '{ printf "%s-%s_%s\n", $3, $5, substr($6,1,2) }')
echo $oldtimestr
newtimestr=$(date -j -f %Y-%m-%d-%I.%M.%S_%p "$oldtimestr" "+%Y-%m-%d-%T")
echo $newtimestr
newfile="screenshot-${newtimestr}.png"
echo $newfile
# mv "$oldfile" "$newfile" # overwrite fienames in place
cp -np "$oldfile" "$newfile" # copy file to same dir, new name
# cp -np "$oldfile" ../TestShots2/"$newfile" # copy file to different dir, new name
fi
done
The date
and awk
utilities are "native Apple" - which is to say they are dated versions from the BSD version of Unix. I think the script will run in a bash
shell also, but I have not tested this.
I've tested the script lightly on my MBP macOS 10.15.6, but made no efforts to "clean it up". It still contains several echo
commands inserted for debugging, and the style is ponderous because I'm not very good at this. There are many improvements that can be made!
I've tested this on my system, and it seems to work. However, I urge caution because Apple is free to change their filenaming format without notice, and I've not tested it thoroughly against a wide variety of fienames.
My test reults:
I created a directory ($HOME/TestShots
) & populated it with files selected from my screenshots folder - the folder that I've configured as destination for all screenshots:
% ls -l TestShots
total 128016
-rw-r--r--@ 1 seamus staff 63497905 Jan 22 2020 Screen Recording 2020-01-22 at 5.22.25 PM.mov
-rw-r--r--@ 1 seamus staff 408602 Oct 22 2020 Screen Shot 2020-10-22 at 11.36.03 PM_R-5100.png
-rw-r--r--@ 1 seamus staff 249838 Jan 1 18:14 Screen Shot 2022-01-01 at 6.14.53 PM.png
-rw-r--r--@ 1 seamus staff 101905 Jan 10 18:44 Screen Shot 2022-01-10 at 6.44.47 PM.png
-rw-r--r--@ 1 seamus staff 61287 Jan 10 19:31 Screen Shot 2022-01-10 at 7.31.51 PM.png
-rw-r--r--@ 1 seamus staff 315761 Jan 11 22:44 Screen Shot 2022-01-11 at 10.43.55 PM.png
-rw-r--r--@ 1 seamus staff 75392 Feb 1 14:32 Screen Shot 2022-02-01 at 2.31.54 PM.png
-rw-r--r--@ 1 seamus staff 274953 Feb 8 00:33 Screen Shot 2022-02-08 at 12.33.23 AM.png
-rw-r--r--@ 1 seamus staff 274220 Feb 8 00:37 Screen Shot 2022-02-08 at 12.37.40 AM.png
-rw-r--r--@ 1 seamus staff 268142 Feb 9 18:01 Screen Shot 2022-02-09 at 6.01.29 PM.png
After running the above script while using the # copy file to same dir, new name
"option" :
% pwd
/Users/seamus
% ./shotfnmv.sh | less
% ls -l TestShots
total 132008
-rw-r--r--@ 1 seamus staff 63497905 Jan 22 2020 Screen Recording 2020-01-22 at 5.22.25 PM.mov
-rw-r--r--@ 1 seamus staff 408602 Oct 22 2020 Screen Shot 2020-10-22 at 11.36.03 PM_R-5100.png
-rw-r--r--@ 1 seamus staff 249838 Jan 1 18:14 Screen Shot 2022-01-01 at 6.14.53 PM.png
-rw-r--r--@ 1 seamus staff 101905 Jan 10 18:44 Screen Shot 2022-01-10 at 6.44.47 PM.png
-rw-r--r--@ 1 seamus staff 61287 Jan 10 19:31 Screen Shot 2022-01-10 at 7.31.51 PM.png
-rw-r--r--@ 1 seamus staff 315761 Jan 11 22:44 Screen Shot 2022-01-11 at 10.43.55 PM.png
-rw-r--r--@ 1 seamus staff 75392 Feb 1 14:32 Screen Shot 2022-02-01 at 2.31.54 PM.png
-rw-r--r--@ 1 seamus staff 274953 Feb 8 00:33 Screen Shot 2022-02-08 at 12.33.23 AM.png
-rw-r--r--@ 1 seamus staff 274220 Feb 8 00:37 Screen Shot 2022-02-08 at 12.37.40 AM.png
-rw-r--r--@ 1 seamus staff 268142 Feb 9 18:01 Screen Shot 2022-02-09 at 6.01.29 PM.png
-rw-r--r--@ 1 seamus staff 408602 Oct 22 2020 screenshot-2020-10-22-23:36:03.png
-rw-r--r--@ 1 seamus staff 249838 Jan 1 18:14 screenshot-2022-01-01-18:14:53.png
-rw-r--r--@ 1 seamus staff 101905 Jan 10 18:44 screenshot-2022-01-10-18:44:47.png
-rw-r--r--@ 1 seamus staff 61287 Jan 10 19:31 screenshot-2022-01-10-19:31:51.png
-rw-r--r--@ 1 seamus staff 315761 Jan 11 22:44 screenshot-2022-01-11-22:43:55.png
-rw-r--r--@ 1 seamus staff 75392 Feb 1 14:32 screenshot-2022-02-01-14:31:54.png
-rw-r--r--@ 1 seamus staff 274953 Feb 8 00:33 screenshot-2022-02-08-00:33:23.png
-rw-r--r--@ 1 seamus staff 274220 Feb 8 00:37 screenshot-2022-02-08-00:37:40.png
-rw-r--r--@ 1 seamus staff 268142 Feb 9 18:01 screenshot-2022-02-09-18:01:29.png
Note that the filename Screen Recording ...
was not re-formatted iaw the script logic, and that the non-standard Screen Shot
filename ending in PM_R-5100.png
was re-named, but the "customized" portion of the filename was lost.
Hope you find this useful & let us know if there are questions.