Every day I need to download a lot of pictures in a row through the Google plugin, concentrated in a few minutes. So I want to have a script that can clearly let me know that the download tasks currently in progress by Google have all been completed, so that I can easily go to the next processing flow.
My main reference materials are:
1. Keyboard Maestro with lsof command
According to the first scenario, I have used the command
lsof -c /Chrome/i | grep "/Users/ifxl/Downloads/tmp_images/ref"
lsof -c /Chrome/i | grep "/Users/ifxl/Downloads/"
However, this judgment is very unstable, and it is often judged too early that the download has been completed, but in fact it is not.
#! /bin/bash
export LANG="en_US.UTF-8"
PATH=/usr/local/bin:$PATH
dir="/Users/ifxl/Downloads/tmp_images/ref/"
# check whether $dir exists
#test -d "${dir}" || exit 1
last=0
current=1
while [ "$last" != "$current" ]; do
last=$current
current=$(find "${dir}" -exec stat -c "%Y" \{\} \; |
sort -n | tail -1)
sleep 10
done
echo "directory is now stable..."
This method will pop up an error reminder:
stat: illegal option -- c
usage: stat [-FLnq] [-f format | -l | -r | -s | -x] [-t timefmt] [file ...]
Is there a very elegant way to determine that all downloads have been completed in Google Chrome.
Or, is there a very ingenious way to achieve a very accurate judgment?
# into the parent folder which download files exsit.
cd /Users/ifxl/Downloads/tmp_images/
# count how many seconds the final folder exsit
echo $(( $(date +%s) - $(/usr/bin/stat -f%c ref) ))