This is an improvement to previously discussed: Constantly check folder for specific file type and run terminal command with new filename as an argument
I used to love Automator for such tasks, but found in this task passing arguments with filenames in Automator steps failing for me. I'm open to good script as well.
I have an Intel and M2 Macs, old one is portable and I found M2 is recoding (lower res and crop) video faster than Intel would even with sending results over WiFi. Puzzling myself to do following
Samba share on M2 accessible over WiFi
Either edit (if was emptied in step 4) or new file queue.txt with YouTube link. Folder MMi is needed in step 4 for correct work
A nifty programs entr and yt-dlp looking at updates in queue.txt and if there is new - downloading 720p .webm video as example https://www.youtube.com/watch?v=WO2b03Zdu4Q
ls queue.txt | entr yt-dlp -q -f "best[height<=720]" --batch-file queue.txt
yt-dlp conveniently adds .part to file in download progress not to interfere with following steps, once it's completed a script (thanks to @nohillside) picks up encoding:
while :; do ls . | find . -depth 1 -type f -iname "*.webm" -exec sh -c ' f="$1" mv -- "$f" MMi/ handbrakecli --encoder x264 --width 800 --format av_mp4 --optimize --non-anamorphic --rate 30 -i "MMi/$f" -o "MMi/${f%.webm}.mp4" rm "MMi/$f" cat /dev/null > yt.txt ' _ {} \; done
As it's finished, need to rsync it back to Intel Mac over WiFi (ssh keys are already exchanged)
rsync MMi/*.mp4 user@intel_mac/MMi
Is there a way to combine everything in one script, other than maintaining three "daemon", maybe launchctl on a .plist or python program?
Are there guides or templates to get this script running as a daemon on macOS?