3

I'm trying to combine these two commands:

while :;do screencapture -x ~/Desktop/$(date +%y%m%d%H%M%S).png;sleep 300;done 

and

imagesnap -t 300

I want to make a screenshot and a webcam photo at the same time every 5 minutes. It's my first time using the terminal, so I'm very new to this. It's probably very simple but I just can't figure it out.

Thank you for helping!

2 Answers 2

1

Something to try, add an ampersand to the end of your commands.

imagesnap -t 300&

The idea here is that the ampersand will cause the command to run in the background allowing the loop to continue to the next step.

As an example, if you were to run the following in Terminal you'll see that the second sleep reports out before the first one.

sleep 10&; sleep 5&;

I hope this helps

0

Using a while loop together with imagesnap -t 300 will end up with screenshot and webcam getting out of sync rather quickly. Might be better to use

while sleep 300; do
    timestamp="$(date +%y%m%d%H%M%S)"
    screencapture -x ~/Desktop/"screen-${timestamp}.png" &
    imagesnap -q ~/Desktop/"cam-${timestamp}.png" &
done

Putting the sleep into the condition allows to easily terminate the loop with Ctrl-C, running the capture commands in the background is the best we can do on shell level to have them execute at the same time.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .