Submission: "Hot Screen" Applescript
  • I want to see active cameras bubble up to a more prominent view on the screen, and then automatically go back to an all-camera view, so I wrote this AppleScript. Annoyingly, this forum eats the whitespace formatting but I think just cut/pasting it into AppleScript Editor will do the right thing.

    -- SecuritySpy "hot screen" script v1.0
    -- 2014/11/01 John Todd
    -- Load this script into AppleScript Editor, and save as an scpt file to:
    -- ~/Documents/SecuritySpy/Scripts
    -- Then for all your cameras in SecuritySpy, attach this
    -- script as an "action".
    -- I leave my SSpy machine in "full grid" mode when it is idle,
    -- so I can see a quick view of all the cameras. However, when
    -- there is motion detected, I'd like to see just those cameras that
    -- are having motion events. This focuses in on the cameras that
    -- are in "motion detect" mode, and shows them in full screen. When
    -- the events are completed, it goes back to full grid.
    -- Improvements welcome.

    on run arg
    set camNumber to item 1 of arg
    set totalCams to 16 -- set this to the number of cameras in your system
    set activeCams to totalCams - 1
    set currentCam to 1
    set recording to ""

    tell application "SecuritySpy"
    enter full screen mode
    add full screen camera number camNumber -- immediately show MD camera (no test needed)

    repeat while activeCams > 0 -- as long as there are any cams doing MD, loop

    set activeCams to totalCams - 1
    repeat until currentCam = totalCams -- loop on all cameras

    -- if we try to look at a motion detection file for a camera
    -- that isn't recording an MD file, it throws an error. Trap
    -- the error and use that error to indicate that this camera should
    -- not be shown on the "hot screen".
    set recording_test to (get current MD file camera number currentCam)
    on error errMsg number errorNumber
    remove full screen camera number currentCam
    set activeCams to (activeCams - 1)
    set recording_test to null
    end try

    -- if there is currently an MD file being recorded, then
    -- we want to see it on the hot screen.
    if (recording_test is not equal to null) then
    add full screen camera number currentCam
    set activeCams to (activeCams + 1)
    end if

    set currentCam to (currentCam + 1) -- increment counter for loop

    end repeat
    set currentCam to 1 --aaaand wash, rinse, repeat.

    delay 3 -- pause for a bit to give the machine a break
    end repeat

    -- Now that we're out of the motion detection events,
    -- set the screen back to showing all cameras in a grid, and exit.

    set currentCam to 1
    repeat while currentCam < totalCams
    add full screen camera number currentCam
    set currentCam to currentCam + 1
    end repeat

    end tell

    end run
  • Thanks for posting this! Looks great. Hopefully will be useful for other users.
  • I am currently testing your script on my 5 camera system. So far, it appears to be almost exactly what I was attempting, but you seem to have much more AppleScript knowledge to make it happen.

    I did change two of your comparators on the repeat arguments which I believe are bugs that you will want to change also. I could see what your script was doing before I changed those, but it wasn't quite right. I also pasted in the code to make the computer announce which camera was triggered and to only "activate" SS if the machine has been idle for more than 30 seconds. Thank you so much for sharing.

    By the way, is free and anonymous, no login required and offers AppleScript syntax highlighting.
  • I found an 'off by one' error as well that you found and fixed with the comparator change - I changed it by moving "1" to "0" but the comparator change works too.

    I'm trying to get the "flicker" issues down to a minimum, as well, when there are multiple cameras that get activated. On a not-so fast machine, it gets kind of herky-jerky when adding/subtracting cameras. I think there are also issues with multiple cameras and multiple instances of the script launching where things get duplicated - I'll try to put some durable state machine stuff in there with the 'properties' option in Applescript so that it bails out if there's already one instance of the script running. Catching edge cases is where simple programs go to pieces. :-)

    I'm actually learning Applescript as I go here - it's a bit hackish, but gets the job done.

    I like Pastebin, but I'm a believer in pasting configs into forums - I've found too many dead links over the years, and this is the kind of stuff that will be read by someone in 2020 or beyond.

  • Any new updates to this script, I am having an issue when 1 camera gets triggered it opens another camera with it that has no motion detected. would be good if ben can implement this in securityspy software
  • Hi @jtodd and others

    I have used a derivative of your script for years, and something (my guess is Mojave) made it stop working. I thought I will try your original but Script Editor won’t save it, says 'Expected "," but found identifier.' I have tried to figure it that out, unsuccessfully. Can you or anyone help? Thanks!
  • There have been some subtle changes in the way AppleScripts are handled in SS recently, so this could be the issue (basically we had to re-write scripting support from the ground up to modernise the code for newer macOS systems).

    Can you tell me what line of code it's failing on? I may be able to suggest a fix.

    One change has been that the "add full screen" and "remove full screen" commands now return an error if you specify an invalid camera number. Instead of the above looping code, to add/remove all cameras to the full screen view, specify a camera number of -1:

    add full screen camera number -1
    remove full screen camera number -1

Howdy, Stranger!

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