Delay capturing image file in script?
  • Hi,

    I'm working on a simple Apple Script to capture a still image and email it to me.

    The problem is that sometimes I receive the email with the correct image, sometimes I get no image, and sometimes I get the last image. This makes me thing that the Capture command is triggering an asynchronous image capture, and that the command completes and my script moves on to the next command before the Capture has actually completed.

    Would this be the case, or should the Capture command not return until the images is captured and stores on disk, i.e. a synchronous operation.

    If Capture is asynchronous, how can I tell when it has completed?

    Thanks
  • You are correct in that the command is asynchronous; after the command is issued, SecuritySpy has to wait for the next frame to come in before it can capture it. A simple "delay 1" after the "capture image" command should resolve this.

    If you want to be a bit more sophisticated about it, you could do the following:

    - Delete any previous image
    - Issue the "capture image" command to SecuritySpy
    - Wait 1 second
    - Check in your script whether the file exists, something like this:

        tell application "System Events"
            if exists file "/path/to/file" then

            end if
        end tell

    Then you can only take action if the file has actually been captured. There may be some other problem (e.g. the camera going temporarily offline) that prevents an image from being captured.
  • Thanks, but it's sounding like I have a more complex problem going on. I had a delay 2, and thinking that might be too little, changed it to a delay 10. And today I got no image.

    My working theory is that when I got an old image, the email & attachment were sent before SecuritySpy even started rewriting the image file. And that when I get no image it's another intermediate point where the old file has been erased but the new not yet written. But I can't prove this. It's just consistent with the behavior. These image captures are triggered once a day, so it's possible that the disk has spun down and writing the new file could take a few seconds, but 10 seconds sure sounds like it should be plenty long to wait.

  • The maximum delay you should expect depends on the frame rate of the incoming video stream. Assuming the frame rate is above 1, then you should not have to wait more than 1s for a frame to be captured after you ask for it.

    If SecuritySpy encounters any error writing the file, it will note this in the log (File menu in SecuritySpy -> Open Log), so check this for any relevant errors.

    The other possibility is that the camera is going offline for short periods of time for some reason (e.g. due to an intermittent WiFi connection or other temporary network issue). Again, in this case, the log file should give some clues as to what could be going wrong.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!