I'm looking to do some operations against recorded files after they have been fully written to disk. I see that there is the option of using AppleScript as an Action. But I am unclear how to get the filename of the captured event out of it.
Here is my scenario: I want to use the alpr software to detect license plates. I want to run this each time a new capture event is written to disk. I do not want to start the action until the recording is finished, and the recording file is closed. I would like the ability in the SecuritySpy UI to "run script after capture" I would like to use any type of script, ideally a bash shell script, or even python.
I also have interest in openALPR and more general script integration (other than Applescript) - spawining a (ba)sh process would be ideal. I've not done more than build openALPR to check capability so far, but was thinking of piping action emails containing the images into it.
There is currently no option to run a script after a file is captured, but I can certainly see how this would be useful. I'll see if we can add this in a future update.
As it's an advanced feature that won't be useful for most users, I didn't want to clutter the UI with a new setting for it. So, what you need to do is create a script using Script Editor and save it with the name "ProcessCapturedFile" in the ~/SecuritySpy folder (i.e. the SecuritySpy folder within your Home folder). It must have the file extension ".scpt" (this is added by Script Editor by default).
If this script exists, SecuritySpy will invoke it whenever a captured file has finished, and will pass in the camera number, camera name, and file path as parameters. Here's an example script that demonstrates how to get the parameters:
on run args set cameraNum to item 1 of args set cameraName to item 2 of args set filePath to item 3 of args end run
Note that it will be invoked for all captured files - movies and images. If you want to ignore images, then you'll need to check the file extension for .mov or .m4v files, and ignore .jpg files.
Please test this and let me know if it works as expected.
I put the ProcessCapturedFile.scpt script on the Script folder on my SS user folder and set the script as action of a webcam. Set the Webcam active with ACTION but nothing happen. (works with other script, so isn't a SS configuration mistakes.)
on run args set cameraNum to item 1 of args set cameraName to item 2 of args set filePath to item 3 of args display dialog cameraNum & cameraName & filePath end run
Hi @martinorob the location of this script must be within the SecuritySpy folder itself, and NOT the Scripts folder within the SecuritySpy folder. The Scripts folder is for scripts that can be invoked upon motion detection - this is different. This script will be invoked for every captured file that is created, including continuous-capture files and JPEG files.
HI Ben, yesterday I have putt my webcam in continuous mode with a file creation every hours. Using the script above, every hour I have a telegram notification. I think that the ProcessCapturedFile.script trigs on the Continuous capture "file cut" time.
Yes, the script will be invoked when ANY captured file is created.
You can distinguish motion-capture movie files from continuous-capture movie file by the presence of the string " M " vs. the string " C " in the file name, for example like this:
if filePath contains " M " then do something end if
Note the space characters around the M and C. And make sure that no other folder within the path, nor the camera name itself, contains this string.
The invocation of this script, or the fact that a new media file has been written can be quite useful in the event stream. Please consider adding more events. :) EDIT: I'd like to see events like this so I can keep track of recorded files without calling the ++download method.
In the case of the request here: https://www.bensoftware.com/forum/discussion/2679/attaching-video-to-imessage - if the created file was in the event stream, the doorbell push could just invoke sending the last recorded file for camera X. I'd like to integrate something like this into the Go SDK so it can be exposed in other apps. Reading through some of the feature requests in the forums makes me believe that with the right events in the stream, a "sidekick" Go daemon could fit users' needs.
i @Ben, is there any way to retrive the Motion Detection "cause"? I use the script above for push notification on telegram but I can't find a way to add the cause of the motion detection (like "motion detected human" or "motion detected sound").
Hi @martinorob, sorry this information is not passed to the script at this time. I'll see if we can add this.
In addition, the ProcessCapturedFile script is not the best way to generate notifications for motion detected, because it is only invoked when a captured files has finished, which can be some time after the actual motion event that caused it.
A better way would be to put your custom script into the ~/SecuritySpy/Scripts folder, and then set this as an action for the camera(s) in question. But again there is no way to get the trigger reason from such a script, as yet.
okay thanks, I hole in the next release because some time I receive alert fort sound but if I view nothing is moving so I need to know which is the cause (human, car, sound...)
"A better way would be to put your custom script into the ~/SecuritySpy/Scripts folder, and then set this as an action for the camera(s) in question. But again there is no way to get the trigger reason from such a script, as yet."
@Ben may the same script works as action father the camera? (the question is if the action pass the 2 argument even if I attach the script as the action or I need to modify the script)
@Ben, is there any way to have the path of the captured image and the captured video passed to the apple script as argument? I know that the 3rd argument is the path but not the name of the file..
OK, for AppleScripts triggered as Actions, I have now added the trigger reason as a parameter that gets passed to these scripts. This is now in the latest beta version of SecuritySpy (currently 5.0.2b8).
The parameters passed to the script are now as follows:
1. The camera number 2. The camera name 3. The reason for the trigger, which is a comma-separated list of the following reasons: Motion,Audio,Script,CameraEvent,WebEvent,OtherCamera,Manual,Human,Vehicle
Please confirm that this works as expected. Note that you might have more than one trigger for the event.
As for the ProcessCapturedFile script, the third parameter is the full path to the captured file - including the file name itself (as the final path component).
hi Ben, I'm no more able to run my script.. may you try please? Or tell me how I ca troubleshoot my script with ss? If I pas manually arg to my script from shell it works.. but SS do nothing..
ok ok on ProcessCapturedFile script there is no new arg true? So, i'm trying to adapt my script to run as Action and not as ProcessCapturedFile script but I can't find any way to retrive the motion capture file path to pass as video file.. may you help me?
do shell script "/usr/bin/curl -s -X POST https://api.telegram.org/botKEY/sendPhoto -F chat_id=ID -F photo='@/Users/user1//SecuritySpy/Scripts/'" & cameraName & "'.jpg'" end run
Hi @martinorob, the ProcessCapturedFile script is called for every file that is created, not just files created in response to motion triggers. In addition, this script is called when the file is finished, not at the time of the trigger. Because of these reasons, there is no "trigger reason" parameter passed to this script.
Conversely, the script that is called as an Action does have the trigger reason parameter passed to it, because a trigger always invokes the Action, and the script is run at the time of the trigger. However, Actions are separate from any kind of recording - it's very common to have an Action without a recording - and therefore no file path is passed to this script.
So, you can either be notified of file completion via the ProcessCapturedFile script, or of motion triggers via the Action script. If you want to be notified of a Motion Capture recording, and also obtain the trigger reason, then it's probably best to have your script invoked as an Action, and then use the "get current motion capture file" to check for a recording. Note however that this file won't be usable until recording has finished.