How to send an image via email every x minutes/hours?
  • Is there something in the settings that would allow me to send an image from a camera every x minutes or hours? I can't seem to find a way to set that up. Am I missing something? I see a means in the Continuous Capture tab of setting an image capture frequency every x seconds and uploading it to a server, but is there a way to have it sent via email instead of uploading it? Thanks in advance for any help!
  • There is no built-in feature in SecuritySpy to do this (such a feature has never been requested!) but you could use AppleScript to achieve what you want. You can write AppleScripts using the Script Editor software that comes with every Mac.

    Firstly, make sure that Mail is set up on this Mac with the ability to send emails.

    Here's a script that will grab an image from SecuritySpy and send it to an email address:

        tell application "SecuritySpy"
            capture image camera number 0 as "/tmp/ss-temp-image.jpg" with overwrite
        end tell

        delay 2

        tell application "Mail"
            set theSubject to "Image From SecuritySpy"
            set theAddress to "me@example.com"
            set theAttachmentFile to ":tmp:ss-temp-image.jpg"

            set msg to make new outgoing message with properties {subject:theSubject, visible:true}
            tell msg to make new to recipient at end of every to recipient with properties {address:theAddress}
            tell msg to make new attachment with properties {file name:theAttachmentFile as alias}

            send msg
        end tell

    Make sure to specify the correct camera number in the script (you can see this in the Camera Info window when you have enabled the appropriate column).

    You can use Automator to run this script at regular emails.
  • Thanks for this, Ben! It's been over a month and I just got around to trying it. Everything seems fine but for the fact that no image is attached in the email, no matter which camera number I use. I'm stumped. I know I've got the right camera numbers. It just seems like there's some disconnect somewhere between:

    capture image camera number 0 as "/tmp/ss-temp-image.jpg" with overwrite

    and

    set theAttachmentFile to ":tmp:ss-temp-image.jpg"

    and

    tell msg to make new attachment with properties {file name:theAttachmentFile as alias}

    Do you have any suggestions?

    It would be a handy feature within SecuritySpy (hint, hint).

    Thanks!
  • In the Finder, select the "Go to Folder..." option under the Go menu, and enter /tmp to get to the temporary folder. When you run your script, do you actually see an image file being created here?

    I'm not sure about implementing this as a feature in SecuritySpy as I don't think this would be useful for most users. Also, frequent emails of the same type from the same source tend to be blocked by spam filters. Is there any particular reason why you want emails rather than, say, using our SecuritySpy iOS app to monitor your system?
  • Yes, the file gets written there, but it doesn't get attached to the email that's sent. I can't see anything in the script that would cause it to not be included as an attachment so I"m baffled.

    I'd just want an email like every couple of hours or so, as a kind of check in to the site I'm monitoring, because there are times when I get no notifications of any kind of event, but I'd still like a nudge to see what's going on, what things look like. The script you've posted ought to be a fine way to do that, but I can't figure out why the attachment isn't being placed in the email that's going out.

    Thanks!
  • I've done some further testing and it seems that there is sometimes a bit of a delay after telling Mail to attach the file, before the file is actually loaded and attached. Perhaps Mail does this in the background and if the email is sent too soon, it will go without the attachment. So, try putting a "delay 5" before the "send msg" command. Does that do it?
  • Awesome, thank you! In my case it needed a delay 10, but whatever. Thank you for hammering on this, it's greatly appreciated!
  • Great to hear that did the trick!

Howdy, Stranger!

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