Follow us @bensoftware

SecuritySpy

Multi-camera video surveillance software for the Mac

Back to help


AppleScript Examples

AppleScript is the a scripting language that is widely supported by Mac applications and used to automate tasks. SecuritySpy understands many commands to capture images, arm and disarm camera modes, and set various settings. You write scripts using the "AppleScript Editor" application in the /Applications/Utilities/ folder.

AppleScripts can be run from within the AppleScript Editor application, or alternatively saved as applications themselves, so they can be opened directly from the Finder and run independently. To do this, open a script in AppleScript Editor, choose Save As... from the File menu, choose Application as the File Format, make sure the Startup Screen option is disabled, and save the new script application:

To view the AppleScript commands supported by SecuritySpy, open AppleScript Editor, select Open Dictionary from the File menu, and select SecuritySpy. You can also view the SecuritySpy AppleScript commands here.


Regular Image Capture

This script demonstrates a regular image capture. The script tells SecuritySpy to capture one frame every 10 seconds from camera number 0, and saves it to disk into a "Captures" folder created on the Desktop, with a set file name depending on the current date and time.


Triggering Motion-Detected Recording

This script simulates motion on camera 0. This could be useful to trigger a recording based on an external sensor such as a switch, infra-red sensor or doorbell.


Enabling and disabling a camera, and setting camera settings

This script enables camera 0, and then disables it. This uses the camera settings HTTP POST request in SecuritySpy, so SecuritySpy's web server must be enabled. Make sure to modify the "formURL" address with the correct IP address and port of your SecuritySpy web server. If you have enabled authentication you can additionally add this to the url as follows:

http://username:password@<ip-address>:<port>/++camerasetup

All camera settings can be set in this way using POST requests - to see the parameter names, have a look at the source code for the ++camerasetup HTML page available through the web server.


Send iMessage

This script captures an image file from a camera and sends it as an iMessage via the Messages app. You'll need to edit the script to set the correct camera number and recipient's phone number or email address (which must be in your address book). This script can be set in SecuritySpy as an Action to be performed upon motion detection.


Pan/Tilt/Zoom Auto-Patrol

This script periodically tells camera 0 to move to PTZ preset 1, then preset 2, then preset 3. You should modify this script to add the presets you want to patrol, and also you can change the delay period (which is currently 10 seconds).


Button Click Image Capture

This script will present a small window with two buttons: "Stop" and "Capture". Click the Capture button repeatedly to capture still images from a particuliar camera; each image will be saved to disk and numbered sequentially, with an additional session number so that you don't have to empty the destination folder before starting a new capture session. Before running this script, in the "capture image" command, set the correct camera number, and set the path to a valid directory within your Documents folder.


Camera Settings Change

The camera settings can be set via SecuritySpy's built-in web server, and so to set the settings from AppleScript, simple scripts can be written that post data to the web server. The example below turn motion detection off and on for camera 0.

In this way, you can have a quick script that changes some key settings for a camera - and if required, this can be scheduled on a regular basis using CronniX. If you have enable password protection for your SecuritySpy web server, you will have to enter the username and password in the "PathToServer" URL. The IP address "127.0.0.1" used in the above script universally refers to "this computer", so should work in all circumstances, no matter what your actual computer's IP address is. Many settings are available, below are some of the most useful ones. Note that you must include the action=save parameter, as demonstrated above, to tell SecuritySpy to save the settings.

camEnabledCheck0 or 1Disables or enables a camera
mdCheck0 or 1Turns motion detection off or on
mdSensitivityText0-100The motion detection sensitivity
mdSoundTriggerCheck0 or 1Whether sound triggers motion detection
mcCaptureMovieCheck0 or 1Turns motion movie capture off or on
ccCaptureMovieCheck0 or 1Turns continuous movie capture off or on

Parse System Info

There is a "System Information" request available via SecuritySpy's web interface, which contains a wealth of information about each camera such as the resolution, mode and connection status. As a demonstration, this script gets and parses this information, and displays a message when a camera is offline. Instead of a message, you might find it useful to send an email to notify you of an offline camera, or link it up to a home automation system that automatically power-cycles the offending camera in an attempt to bring it back online.

For this script to work correctly, you will need to enable SecuritySpy's web server, and modify the "username:password" string in the script to match the authentication of a web server user account with full access priviledges (i.e. including general settings).


Scheduling Scripts

To schedule scripts to be run regularly at certain times, you can use CronniX, which is a graphical front-end to the powerful Unix scheduling tool cron. Using this tool you can schedule either simple one-line commands, or script files.

Open CroniX and click the "New" button to add a new task. To schedule a one-line command, use the formulation shown below - in this example, the task will tell SecuritySpy to recall the first PTZ preset position for camera 0, every day at 10:00:

In the following example, the script at /Users/ben/Documents/MyScript.scpt will be run every day at 10:00:

When scheduling a task, use the "Simple" setup in CronniX. An asterisk next to any of the timing parameters means that the command will execute for all values of that parameter (e.g. if the "Day of month" parameter has an asterisk, this means that the task will be executed every day of the month). When you are finished with your CronniX setup, click the Save button to save your scheduled tasks.