I take four screenshots from a Client-Server app that isn’t scriptable using cmd-shift-4 space click. I need a script that will take those four .pdf files, rename them with preset filenames, and move the files from the desktop to a user selected folder. The screen shots will always be taken in the same order or sequence, so the time stamp in the filenames can be used to rename the files with the correct preset filename.
Example:
Screen Shot 2020-08-21 at 5.31.54 AM.pdf will be renamed “02xxx_JDB03_Billings & Payments.pdf”
Screen Shot 2020-08-21 at 5.32.06 AM.pdf will be renamed “02xxx_JDB04_Subk Admin.pdf”
Screen Shot 2020-08-21 at 5.32.26 AM.pdf will be renamed “02xxx_JDB08_Peer Reviews.pdf”
Screen Shot 2020-08-21 at 5.32.41 AM.pdf will be renamed “02xxx_JDB10_Schedule & Billing Flow.pdf”
I used creation date to sort the source files but this requires some testing to insure it works OK (It did on my computer). You could sort by file name but that would break if, for example, one screenshot was taken at 9:59 AM and the next at 10:00 AM. As written, existing files in the destination folder are overwritten.
set destinationFolder to choose folder
set newFileNames to {"02xxx_JDB03_Billings & Payments.pdf", "02xxx_JDB04_Subk Admin.pdf", "02xxx_JDB08_Peer Reviews.pdf", "02xxx_JDB10_Schedule & Billing Flow.pdf"}
tell application "Finder"
set sourceFiles to every file in (path to desktop) whose name begins with "Screen Shot"
if (count sourceFiles) is not equal to 4 then display alert "The number of screen shot files on the desktop is not equal to four." buttons "OK" cancel button 1
set sortedFiles to sort sourceFiles by creation date
repeat with i from 1 to 4
set name of item i of sortedFiles to item i of newFileNames
end repeat
move (every file in (path to desktop) whose name begins with "02xxx") to destinationFolder with replacing
end tell
It occurred to me that you might want to move the Screen Shot files to a different volume, in which case the Finder move command does a copy. If that becomes an issue, the simplest solution is to delete the Finder move command and to add the following shell command at the end of the script:
do shell script "mv -f " & (quoted form of POSIX path of (path to desktop)) & "02xxx* " & quoted form of POSIX path of destinationFolder