Here is the first script that you would run manually from the Terminal without any arguments. It will graphically prompt for a folder selection that contains your camera images. As written, it will process only the files created between 9:30pm and 5am inclusively, ignoring the rest whose creation time does not satisfy the time range. If you instead, do not want files created exactly at 9:30pm or exactly at 5am to be removed, then change 2129 and 0501 to 2130 and 0500 respectively.
I have left the line in the code that removes (rm) commented, as I would prefer that you test this on a subject of your image in another folder to assure that it is selecting the correct files. I have tested it, but you may want to read the report that it produces, before you uncomment the (rm) line, and turn it loose on live images.
Copy and paste the content of this script into a plain text document that you save to your Desktop as arbitrary_name.zsh. In Terminal, you would mark the script executable, and then run it as follows:
cd ~/Desktop
chmod +x ./arbitrary_name.zsh
./arbitrary_name.zsh
Code:
#!/bin/zsh
: <<'COMMENT'
Present a graphical folder chooser to pick the folder enclosing the security
camera images. Remove any files in this folder selection whose creation time
is at, or after 9:30pm (2129), or at or before 5am (0501)
Run this script from the Terminal command-line, after making it executable:
chmod +x txd.zsh
./txd.zsh
Uncomment the remove (rm) statement after testing on a sample folder, and
reviewing the Desktop/rpt.txt file.
COMMENT
RPT="$HOME/Desktop/rpt.txt"
# Select the folder containing the camera images
function folder_prompt () {
osascript <<-AS
use scripting additions
return POSIX path of (choose folder default location (path to desktop))
AS
}
function report_files () {
local tm=$1
local fp=$2
# headers only if file does not yet exist
[[ -s $RPT ]] || echo "Time\tFile Path" >> $RPT
echo "$tm\t$fp" >> $RPT
return
}
# just in case the folder name begins with an underscore
# and suppress any Finder stderr gibberish to the bit bucket
# sfolder result has trailing '/'
sfolder=$(folder_prompt | sed -e 's/\/ _/\/_/g') 2> /dev/null
# print ${sfolder}
setopt NO_CASE_GLOB
# Case-insensitive loop to get all plain files and no sub-folders
for f in ${sfolder}*.(jp*g)(.N);
do
# extract the time as hhmm from the file creation date
hhmm=$(stat -t '%H%M' -f '%SB' "${f:a}")
# if file creation time is not in range, ignore file and get next one
[[ $hhmm > 2129 || $hhmm < 0501 ]] || continue
# report of files eligible for deletion
report_files $hhmm ${f:a}
# delete individual files that meet time range criterion
# rm -f "${f:a}"
done
exit 0