SecuritySpy - Messages.app and iMessage Integration
  • I've created two scripts that allow you to interact with and control part of SecuritySpy using iMessages and the Message.app

    I've tested this on 10.9 and 10.10, but it may work on older versions of Mac OS X.

    What can you do with this? You can tell SecuritySpy to send you pictures from your cameras when they detect motion. You can tell SecuritySpy to send you pictures of any camera immediately (regardless of active/passive or motion detection settings). These are the main two features of the package. It also provides some other commands so you can control access.

    I recommend you use this with a dedicated SecuritySpy machine ("server"). I made a new Apple ID account specifically for iMessages on this server, and setup Messages.app with this account.

    Installation is simple, but requires a few steps. First, make sure you are signed into an iMessage account with Messages and SecuritySpy is running with at least 1 camera.

    ◆ Copy the file "SecuritySpy Remote Control.applescript" to ~/Library/Application Scripts/com.apple.iChat/
    ◆ Copy the file "SS_SendiMessages.scpt" to ~/Documents/SecuritySpy/Scripts/
    ⁃ The ~ means your home folder, usually something like /Users/yourname
    ◆ Open Messages.app
    ⁃ Go to Preferences > General
    ⁃ Select "SecuritySpy Remote Control.applescript" as the AppleScript handler.
    ◆ Open SecuritySpy
    ⁃ Go to Settings > Camera Settings > Actions
    ⁃ Put a check next to "Run Script" then select "SS_SendiMessages.scpt"
    ⁃ DO THIS FOR EACH CAMERA.

    That's it, it's all loaded. Now, from another computer or your phone send an iMessage to this system with the word "cams" - you should receive a list of your cameras. Send "sub *" to subscribe to all of them. Send "help" for help.

    Thanks! Let me know how it works for you. And, Ben, I apologize if this is not the correct place to post something like this. I just want as many people as possible to have access to this awesome package.

    You can see the scripts (raw) here: http://pastebin.com/anP6Du01
    Download them as a package here: http://www.cartcrafter.com/downlods/SecuritySpy_Remote.zip
    A couple screenshots: http://cl.ly/image/123A4136352s and http://cl.ly/image/100p3s1z1J0N
  • Hi @frankyhall this is great! Very impressive AppleScript programming, I think this will be very useful for many users, many thanks for posting this.

    I can't download the .zip file though (file not found)- is the link correct?
  • I updated the package with a new version. Fixed a few typos and added act/pas commands to allow you set cameras to active or passive. I also updated the paste bin with the new version (currently v0.9).

    I have a couple questions for you Ben:

    1. Is there a way to correlate a camera name with its number? Something like 'get camera number "camera name"' Is what I'm looking for. I would make this script capable of using the number or the name if I had a way to tie the two together somehow. It seems like, via AppleScript, you have to guess at the numbers because there is no "get camera numbers" command like there is for names.

    2. The AppleScript examples page only shows examples of how to interact with SecuritySpy externally. There are zero examples on how to use action scripts that get triggered on motion/audio. I had to dig through the bug reports or forums (I forget where I found it) to even figure out we had args (arg 1 for camera number and arg 2 for camera name). Do you have examples or documentation on running a script from within SS? If not, are there other args?

    As a feature request I would like to be able to access (and change) things like the following, from within a motion script and/or externally:
    - Overlay Text (we have 'set overlay', where is 'get overlay'?)
    - Schedule used by a camera
    - Available schedules
    - Camera Transform settings
    - Disabled cameras
    - Trigger time
    - Camera capture destination
    - After action and After Motion settings (seconds)
    - Camera groups
    - get/set motion capturing or time lapse capturing
    - Whether audio support for the camera is enabled and what audio device it uses.
    - Captured files, sizes, names, locations, durations (I can tie this data into a custom web service)
    - Most of the settings in Preferences.

    I don't do a lot of AppleScript, but when I do I tend to cover all the bases. I'd love to see the suite of AS commands available from SecuritySpy mimic what can be done from the web interface.
  • To answer your questions:

    1. Good point. I have added a corresponding "get camera numbers" command in the latest beta version of SecuritySpy, this should do what you want.

    2. This is a relatively new enhancement and hasn't been documented yet, I will make sure to do so. There are currently just the two arguments (camera number and camera name) passed into the scripts that SecuritySpy invokes.

    3. Most of these configuration options are available via SecuritySpy's web interface, which can be accessed using AppleScript. See the Camera Settings Change AppleScript example for how to do this. The page only lists a few common settings that you can change, however there are much more - if you load the Preferences and Camera Settings pages pages in a web browser and view the HTML source, you will be able to see all the options (i.e. the names of the controls).

    These items are currently not possible to retrieve in a convenient way (i.e. without HTML web scraping):
    - Available schedules
    - Disabled cameras
    - Camera capture destination
    - Groups
    - Audio device used by a camera

    Lists of captured files can be retrieved via XML - let me know if you are interested in finding out about this.
  • Was testing this script this morning and received the following on my server from imessage error when using the "pics" command:

    Event: Message Received
    File: SecuritySpy Remote Control.applescript
    Error: The operation couldn’t be completed. /Users/justin/Library/Application Scripts/com.apple.iChat/SecuritySpy Remote Control.applescript:25873:25897: execution error: AppleEvent handler failed. (-10000)

    Any idea?
  • I'd also add that there needs to be some authentication built into the script. Unles I'm missing something, anyone who knows the iMessage account I'm using could gain access to my cameras...

    Rudimentary authentication such as a list of authorized phone numbers or iMessage accounts, stored in a text file on the server, would be an excellent start.
  • The script isn't perfect, I'll say that real quick. Part of the problem is iMessage sucks at applescript. It is a great example of how to make this integration work though, and if you know how to script I'm sure you can use it as a starting point for your own needs.

    As for authentication: You are correct, anyone with your iMessage account can see "pictures" (not videos) from your cameras. If your account is common knowledge this may not be for you. It suits my needs beautifully and has fit right in with a few of my clients as well. I personally don't care if the Internet has pictures of my porch. It's already a staple on google maps. If you run this at a bank or an adult video store you may want to reconsider. ;)

    At some point I will put a bit more work into this. I may add a password feature of some sort, even though I have no need for it. I plan to integrate it with Indigo too, but that makes it less useful to people without that software. I suppose time will tell what my needs are and what I want to do to it.

    If you still need help making it work, drop me a line and lets figure it out. frankyhall@icloud.com
  • Hi,

    I would like to download the script, but the website is down. Could you please give another link?

    Thanks
  • I would suggest perhaps a "Third Party Addons" folder or location on this website where these things could be uploaded. I know I put some scripts together and just pasted them into a forum discussion, where they'll be lost forever. Ben, any chance of a sanctioned amateur file zone here or as part of the download?
  • JT - that would be a good feature of the web site, though not too easy to implement. I'll see what we can do. Alternatively, users can email us files and we can host them and post the links here.

    Here are some permanent links from our own server to the above files:

    [removed Aug 2015 - please see @frankyhall's github link below]
  • frankyhall,

    Thanks for providing this. Would you be opposed to putting these scripts on github?
  • Not at all, I'll try to do that this week.
  • You can find it on github now. Thanks for the links Ben, but you can remove them now.
    https://github.com/davidnewhall/iMessageSpy

    I'll try to put some time into it, I'm excited that it's under version control. Requests welcome. ;)
  • HELP! I am trying to get this amazing script to work.
    I have followed the instructions but I am getting the following error message whenever I send any message:

    An error occurred while executing an AppleScript event handler.
    Event: Message Received in Active Chat
    File: SecuritySpy Remote Control.applescript
    Error: The operation couldn’t be completed. /Users/abid/Library/Application Scripts/com.apple.iChat/SecuritySpy Remote Control.applescript:4:5: script error: Expected end of line, etc. but found “<”. (-2741)<br />m]"

  • Hi Abid,

    It looks like you have copied the file incorrectly. There should not be any <br /> in it; that is HTML from a webpage.

    Replace the file you have at /Users/abid/Library/Application Scripts/com.apple.iChat/SecuritySpy Remote Control.applescript with this:

    https://raw.githubusercontent.com/davidnewhall/iMessageSpy/master/SecuritySpy Remote Control.applescript

    Hope this helps!
  • Yep you were right, it was HTML.
    I have replaced the file but now getting the following error:

    Event: Message Received in Active Chat
    File: SecuritySpy Remote Control.applescript
    Error: The operation couldn’t be completed. /Users/abid/Library/Application Scripts/com.apple.iChat/SecuritySpy Remote Control.applescript:31044:31050: script error: Expected “given”, “into”, “with”, “without” or other parameter name but found identifier. (-2741)
  • Are you running on macOS Sierra? I've never tested on the latest OS nor have I ever seen that error message before. I'm assuming an Active Chat handler is now required in the newest operating system, but I can't be sure just yet. Perhaps I'll try it out in the next week or so.
  • Yes, its macOS Sierra. Test it at your convenience. No rush. Once done, please update here. Meanwhile I will try it out on macOS Lion 10.7.5.
    Thank you.
  • Remove these line for now and see what happens....

    "
    on received remote screen sharing invitation from theBuddy for theChat
    decline theChat
    end received remote screen sharing invitation

    on received local screen sharing invitation from theBuddy for theChat
    decline theChat
    end received local screen sharing invitation

    "
  • OK did some testing with Sierra and got it to work with the removal of these line in the previous post.

    Bugs that I have seen so far are the following under sierra.
    Pics * only send one of my cameras
    and motion detection doesn't get triggered anymore.

    More testing to be done...

  • Kidney514, I did as you said, removed the six lines.
    At first I had some issues where it was only responding to the first command and thereafter not responding. Did a bit of tinkering around and also used a separate iMessages account rather than using the same one as on iPhone. It works
    How did you figure out to remove those lines? Good work there. I am happy its working on macOS Sierra. I'll see how it goes and report back any issues here.
    Pics also sends one image on mine too.
    Can't try it on my Lion setup as Lion does not have iMessages.
  • Ok was my mistake it works on arm action!
  • This is great news! Thanks for the assistance Kidney514! I'm reluctant to upgrade my security/automation system to macOS Sierra yet, but when I do my scripts will come with me. :)
  • Whether Armed or not, the pics command sends one photo
  • Could this script be amended to work with a Telegram BOT? I typically use Telegram more than iMessages on my phone/PC.
  • The "pics" command seems to work okay for me. I get 7 pictures from my system as expected. iMessages is very finicky to work with using AppleScript and I certainly did my best here. Pull requests to fix bugs are welcomed. :)

    I'm going to try to fix the case sensitivity problem soon, and I'm planning to install Sierra in a VM today. Hoping to give the code a spring cleaning. Keep an eye on github.

    As for making this work with software besides Messages.app: I'd consider coding in Skype support if I had requests for it (I'd use it myself since I already use Skype for video chats with my front door). I'm not sure what Telegram BOT is nor how to interface with it off hand. If you want to amend my code to add new features, I'd be happy to help, but I must ask you to begin the journey for me. Add me on Skype if you want to chat about it. skype://davidnewhall3

    I also added a couple other scripts into my github, used for sending security spy pictures or texts from Indigo Actions.
  • Hi guys, I have updated many aspects of these scripts. I removed bugs, reduced crashing and added features. I also updated the scripts to work on macOS 10.12. There is still a minor bug, present only on 10.12 where the pics command may not send you pictures from every camera. I have isolated this to a problem in Messages.app in the current OS; I cannot resolve it 100% without increasing the delays further. You're welcome to do that yourself to attempt resolution of this problem if you run 10.12 with multiple cameras.

    New Features:
    - stop command can now stop individual cameras. It can still do all of them too.
    - plugin support. You can now write your own small applescripts to use as message handlers. I've included two plugins for demonstration purposes.
    - reset feature. This command will wipe out the plist file(s) used by this script. This is useful when you migrate data from one system to another. I also use it to re-run my tests.
    - Added an installer script. It's safe to run more than once and should be run every time the code is updated. In other words, run `install.sh` after you `git pull`.
    - Make sure you send `reset really` after you upgrade. This will delete the old plist file(s) - those were renamed too. You will also need to subscribe to your camera(s) again.

    I fixed nearly a dozen various bugs. Some caused invalid subscriptions and some caused crashing. The script has a new name: iMessageSpy.applescript (instead of SecuritySpy Remove Control.applescript).

    Lots of pull request history, code comments and a README update at the GitHub: https://github.com/davidnewhall/iMessageSpy

    One last thing, I updated the Restart Messages script to work standalone (without Indigo). This application will prevent Messages.app from getting stuck with a "crash" or "wait" dialog box. Find it here: https://github.com/davidnewhall/IndigoAppleScripts - you'll want to run this if you've ever found Message.app unresponsive due to an error.

    Good luck! Please ask questions and report bugs!

Howdy, Stranger!

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