SecuritySpy info available to AppleScript
  • I am working with Applescript again, and I have come to want my script to know which camera had motion trigger it or which cameras are on the full screen mode. Are any variables passed into the script when it is called? I hope to call the same script from multiple cameras. Thank you.
  • Sorry but no variables are passed into the script at present, though I've just had a look at this and it seems like it would be possible for us to implement this functionality in the future. If you give me a few weeks I may be able to prepare a beta version of SecuritySpy for you to test this out - let me know if you would be interested in this.

    In the meantime you will have to create a separate script per camera and hard-code the camera number into each script.

    There is currently no script to get the list of cameras in full screen mode - the method you would need to use is to remove all cameras and then add just the ones that you want.
  • That is what I had uncovered. I am going to continue trying to find a way programmatically, though I would be thrilled if you were to implement functionality to make it easier and it would be great to test it out. Thanks for the prompt response!
  • Hi - I've just emailed you a link to an updated beta version of SecuritySpy with this functionality.

    Here's an example of what you do in the script:

       on run arg
          display alert "camera number " & item 1 of arg
       end run

    Your script now goes between the "on run" and "end run" lines, and the "arg" parameter takes on all the arguments passed to the script, the first (and currently only) of which is the camera number. The above script simply displays an alert with the camera number.

    For anyone else following this thread, this will be added to SecuritySpy in the upcoming 3.4.2 release.

    Hope this helps.
  • I was excited this was readied so quickly and had to try it out, but I cannot get your example to work. I've tried everything I know to get something out of that variable, but I am definitely a novice at AppleScript. I'll let you know if I work something out on my end. Thanks so much for making this happen!
  • Happy to help! Make sure that the script is being triggered by SecuritySpy as an Action in response to motion detection. So, save it to the ~/Documents/SecuritySpy/Scripts/ folder, and set it as an action for a particular camera. Then trigger motion in that camera to invoke the script.

    Also make sure to quit your old version of SecuritySpy, download the beta version that I linked to in my email, and copy it to your Applications folder, replacing any older version you have there. Just so that there's no confusion as to what version of SecuritySpy you are running. If you "Get Info" on the SecuritySpy app in the Finder you should see that it's version 2.4.2b2.

    That's the error I get when I copy and use your code directly. I've seen a couple other errors trying some changes, but I cannot get any data out of 'arg' or 'item 1 of arg' or 'contents of' stated items. It did tell me at one point 'item 1 of arg' has no value. I think I am testing that arg is not empty though. Indeed I am triggering the script from SecuritySpy's motion detection, and I have verified that the beta version is what is running.
  • on run arg
    display alert "camera number " & arg --removed 'item 1 of'
    end run

    This results in an alert that says "camera number current application".
  • Upon further investigation, it appears you have to save the script as a standard script file (.scpt) and not an application (.app) like you appear to be doing.

    I'm not sure why AppleScript has this limitation but there you go. So save it as a script to SecuritySpy's Scripts folder, set it to trigger, and then you should see that the camera number coming through.
  • Well that was easy! Now it works. I was using .app so as to have the script stay running for quicker response. I haven't even checked yet to see if it's any faster.
  • SecuritySpy beta crashed on me this morning, I am emailing the crash log. I have implemented your arg into my script and I am curious if you had an item 2 in mind, or more. I would like to have one for the camera number last previously triggered. I will gladly share my script once I refine it further.
  • The camera name would be another very useful item.
  • Sorry about the crash, beta versions are works in progress and there may be a few bugs to be ironed out yet, I'll have a look at the log you sent. The camera name is a good idea, I'll add that as the second parameter. As for the camera number last triggered, could you explain why this would be useful?
  • I was in no way bothered by the crash as it's beta software, but I would like to provide you with the crash log if that is useful.

    I am making a script which will say the camera name currently triggered and add it to/display the full screen mode. Then it averages motion checks over a pre-set delay before it removes it from full screen mode if the motion is less than a pre-set threshold. Oftentimes, there is still motion on the previously triggered camera when it's time to add a new one to full screen. I have my script checking if the computer is idle to determine whether to wake the display, bring SecuritySpy to the front, or sleep the display. I am attempting to do it all with one script for all cameras, and though I am facing some hurdles, it is working pretty well. I've found a need for the previous triggered number as well as the time it occurred to ignore it if it's older. I'm currently achieving this with a text file.

    For example, a car visiting my house will trigger a road camera, then a gate camera, then a driveway camera, so I want to display them then remove them from full screen mode, consecutively and programmatically as the motion comes and goes.
  • This sounds great! Very ingenious.

    I've uploaded a new beta (to the same location) that includes the camera name as the second parameter - I hope this helps. I'll see if I can add the previously-triggered camera as an additional parameter soon.
  • I'm glad I was able to convey the idea.

    I implemented the second parameter without a problem.

    I have been successful in creating a text file with the triggered camera number in it so that effectively gives me the previously triggered camera number and the file's modification date will give me the time of that event. Now I am trying to discover how to compare that time with the current time to determine if it occurred in the most recent five minutes or so. The last triggered parameter is only necessary with another parameter that gave me an easy way to do that like the current time in seconds. Feel free to suggest a different route, I am figuring this out as I go.

    Thanks for all your help.
  • CallObserver: Did you have any progress with this applescript? It would be really useful to build on what you've done already with what you describe as a moving perspective for camera focus. I've wanted to do "bubble-forward" views based on activity, and it sounds like you're most of the way there... can you post a link to the script, perhaps?
  • Sorry it took me a couple days to get back to you. I would be happy to share my script. I got a little burned out on it and I have not worked on it in a few days. I was having trouble getting the script to know that it was called again so that each motion detection would keep the screen up as long as required. I started writing to a text file to try to keep track of the current seconds of the day that the script was triggered each time. It's a bit of a mess right now but should work.



    text file

    I hope this gets you going.

Howdy, Stranger!

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