I'm writing a script to batch convert videos into h.265 format which uses repeat with
to go through all videos. It works great for 3 or 4 files at the same time, but my old mac restarts when the number of videos reaches to ~50.
repeat with videofile in video_list
set filePath to POSIX path of videofile
set filePath to esc_space(filePath)
set [folderPath, filename] to split_path_name(filePath)
tell application "Terminal"
activate
do script with command "ffmpeg -hide_banner -i " & filePath & " -vcodec libx265 -tag:v hvc1 " & folderPath & filename & "_hevc.mp4; mv " & filePath & " ~/.Trash"
end tell
end repeat
Therefore, I want to use applescript to achieve the "Queue" functionality: converting limited number of videos in terminal windows (let's say 10) and monitoring if any windows finished executing, activate some remaining tasks if number of active windows is less than 10.
I did some searches and found system event can tell if apps are running, but I'm not sure how to monitoring multiple windows, especially new windows would be activated when some tasks finished.
Any suggestions is appreciated. (shell script is also welcome if it's convenient)