0

If I take screenshots, I integrate MacOS shots with screenshots from Windows laptop. Apple naming patter uses AM/PM and I can reorder by date created. I forced myself to get used to that. BUT I would really want (e.g., once a year) rename all screenshots to have filenames similar to what Samsung phones do. Sorry Apple.... Picture should be named screenshot-YYYY-MM-DD-HH:MM:SS

I am sure other users out there may be similarly picky. Any solution for this out there.

Note, I do not want any prompts. I am after a script that does mass-rename at time of user choosing.

2 Answers 2

1

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.

1

You can use Shortcuts to accomplish this:

Create a new Shortcut and set it to "Use as Quick Action" in Finder. Receive "Files", and if there's no input then "Stop and Respond" with an error message of your choosing.

Repeat with each item in <shortcut input>
  Rename <repeat item> to "Screenshot-<repeat item:creation date:custom:YYYY-MM-dd-HH.mm.ss>.<file extension>"
End repeat

Here, all <angled brackets> are variables in the Shortcuts UI.

A screenshot of the Shortcut after creation

I've created this as a shortcut you can add yourself: https://www.icloud.com/shortcuts/e856d96bb12c42ffb77e10772acf6ac8

Then, to use this just select one or more files in Finder and right click -> Quick Actions -> Rename Screenshots.

To create it: click new and select shortcut details. Then check Use as quick action and check Finder. Then it will let you edit the script in the GUI.

3
  • It works but hits a snag with 2 monitor screenshots. Two files with same creation creation timestamp and one has appendix (2) prior extension. But I will run a splitter script first to eliminate that error. Is there a way in shortcuts to grab first 3 or last 3 chars of the filename in the repeat item (substring (filename,1,3))?
    – userJT
    Mar 14 at 20:09
  • @userJT You can use "Match Text" on the filename with something like (.{3}).{4}$, followed by "Get Group from Matched Text" for group index 1. This example gets (indicated with the (/)) the 3 characters (.{3}) preceding the last 4 characters (.{4}). The "last" is indicated with the $.
    – Ezekiel
    Mar 14 at 20:39
  • @userJT I don't want to give a full tutorial on Regex, but you can play with something like regexr.com with the suggested query to see how it works.
    – Ezekiel
    Mar 14 at 20:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .