run script against output file after writing to disk (openALPR)
  • Hello,

    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.

    What would be the best way to do this?
    Thanks!
  • 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.
  • Thanks Ben!
    Please let me know if you need someone to beta test the "run script after capture" functionality!
  • This functionality has now been implemented, in the latest beta version of SecuritySpy (currently 4.2.7b2).

    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.
  • hi ben, on the 4.2.8b1 32 bit it doesn't works,

    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




    if I run from shell console

    osascript ProcessCapturedFile.scpt 1 2 3

    it works.


    What I'm wrong?

    Thanks

  • 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.
  • Thanks Ban, outside the Script folder it works!

    This is my script if anyone is interested!


    on run args
    set cameraNum to item 1 of args
    set cameraName to item 2 of args
    set filePath to item 3 of args
    set message to "'ALERT ON '" & cameraName
    do shell script "/usr/bin/curl -i -X GET https://api.telegram.org/botSECRET/sendMessage\\?chat_id\\=CHATID\\&text\\=" & message
    if (filePath contains "jpg") then
    do shell script "/usr/bin/curl -s -X POST https://api.telegram.org/botSECRET/sendPhoto -F chat_id=CHATID -F photo='@'" & "\"" & filePath & "\""
    else
    do shell script "/usr/bin/curl -s -X POST https://api.telegram.org/botSECRET/sendVideo -F chat_id=CHATID -F video='@'" & "\"" & filePath & "\""
    end if
    end run
  • 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.

    Is it possible to exclude this behavior?

    Thanks
    Martino
  • 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.

Howdy, Stranger!

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