Security camera script for Indigo

Posted on
Thu Dec 22, 2005 7:30 pm
doctorlambo offline
Posts: 31
Joined: Dec 08, 2005

Security camera script for Indigo

Here is a script I wrote. Specify the trigger...like a motion detector. It will then take as many picures as you want with a big of interval as you want. It will then email them to you, and throw the pics in the trach so nobody sees them on the desktop. I also updated it so it will send your phone a text message, telling you to check your email. Have fun!

Code: Select all
 ---Made by Ian Dopps 2005
---This script will email you 5 iSight pictures that are about 5 seconds apart. It will also send a text message to your phone, telling you to check your email. You can change the number of pictures and time interval if you desire. It will then put the pictures in the trash and close all programs involved so nobody knows. It is great when used with a motion detector trigger in Indigo. Questions? doctorlambo@gmail.com
--- SUBSTITUTE YOUR INFORMATION (NAME) IN 3 PLACES BELOW!


tell application "iChat"
   activate
end tell
delay 2
repeat 5 times ---CHANGE THIS NUMBER TO EDIT THE NUMBER OF PICTURES TAKEN
   tell application "System Events"
      tell process "iChat"
         click menu item "Video Preview" of menu "Video" of menu bar item "Video" of menu bar 1
         delay 1
         click menu item "Take Snapshot" of menu "Video" of menu bar item "Video" of menu bar 1
      end tell
   end tell
   delay 5 ---CHANGE THIS NUMBER TO EDIT THE DELAY BETWEEN PICTURES
end repeat
set mainpath to path to desktop as Unicode text
set need_fold to "iSEEu"
tell application "Finder"
   if not (folder (mainpath & need_fold) exists) then
      make new folder at mainpath with properties {name:need_fold}
   end if
   tell application "Finder"
      move (every file of desktop whose name contains "Video") to (folder "iSEEu" of desktop)
   end tell
   
end tell
tell application "Mail"
   set bodyvar to "Your home security has captured new images. They have been sent to your email inbox."
   set addrVar to "3162205537@messaging.sprintpcs.com" ---PHONE ADDRESS HERE. FOR DETAILS, SEE: http://www.livejournal.com/tools/textmessage.bml?mode=details   
   
   set subjectvar to "CHECK YOUR EMAIL!"
   set newMessage to (a reference to (make new outgoing message))
   tell newMessage
      make new to recipient at beginning of to recipients with properties {address:addrVar}
      set the subject to subjectvar
      set the content to bodyvar
   end tell
   send newMessage
end tell
tell application "Mail"
   set bodyvar to "Here is the photo taken when your motion detector was set off:"
   set addrVar to "doctorlbo@gmail.com" ---EMAIL ADDRESS HERE
   set subjectvar to "Motion Detector Set Off"
   set attachmentVar to "/Users/dopps/Desktop/iSEEu" ---CHANGE FILE NAME HERE (THE USER NAME SHOULD BE THE ONLY DIFFERENT THING)
   set newMessage to (a reference to (make new outgoing message))
   tell newMessage
      make new to recipient at beginning of to recipients with properties {address:addrVar}
      set the subject to subjectvar
      set the content to bodyvar
      tell content
         make new attachment with properties {file name:attachmentVar}
      end tell
   end tell
   send newMessage
end tell
delay 2
tell application "Finder"
   delete folder "iSEEu"
end tell

tell application "iChat"
   close window "My iSight"
   quit "ichat"
end tell
tell application "Mail"
   delay 45 ---GIVE IT AT LEAST 6 SECONDS PER PICTURE TAKEN TO LOAD AS AN ATTACHMENT. OTHERWISE, IT MAY CLOSE MAIL BEFORE IT IS DONE LOADING THE ATTACHMENTS. SO, IF YOU HAVE 3 PICS TAKEN, PUT 18 OR MORE IN PLACE OF THE NUMBER 45 YOU SEE HERE.
   quit "mail"
end tell

   
Last edited by doctorlambo on Sat Dec 24, 2005 4:28 pm, edited 2 times in total.

Posted on
Thu Dec 22, 2005 10:47 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Security camera script for Indigo

Hi Ian,

Another great script. I need to move all these over to the Script Library page. Thanks for the contributions!

Regards,
Matt

Posted on
Fri Dec 23, 2005 12:05 am
doctorlambo offline
Posts: 31
Joined: Dec 08, 2005

(No subject)

Thanks!

Posted on
Tue Sep 19, 2006 4:23 pm
czvi offline
Posts: 79
Joined: Jul 23, 2006

(No subject)

I'm running OS X 10.4 and get an applescript error:

System Events got an error:
NSReceiverEvaluationScriptError: 4


This happens on line:

click menu item "Video Preview" of menu "Video" of menu bar item "Video" of menu bar 1

Thanks.

Posted on
Tue Sep 19, 2006 8:03 pm
rustbuster2 offline
Posts: 21
Joined: Feb 24, 2006
Location: Gatineau, QC Canada

(No subject)

Does anyone have any ideas on how to extend doctorlambo's script to place the pictures on the 2.0 IndigoServer control pages?

Posted on
Tue Sep 19, 2006 10:59 pm
macpro offline
User avatar
Posts: 765
Joined: Dec 29, 2005
Location: Third byte on the right

(No subject)

rustbuster2 wrote:
Does anyone have any ideas on how to extend doctorlambo's script to place the pictures on the 2.0 IndigoServer control pages?

I haven't tested this, but you could try the following:
- Copy the pictures into the folder Library>Application Support>Perceptive Automation>Indigo 2>IndigoWebServer>images>controls>static
- Give them always the same name "pic1.png" ... "pic5.png"
- Make sure they are saved in ".png" format
- Define a control page and add 5 buttons to the page based upon these pics.

Whenever the script takes new pictures, it should replace the old ones.
The control page should automagically refresh when it sees the new pictres, so no action needed there.

Posted on
Tue Sep 19, 2006 11:55 pm
dtich offline
Posts: 798
Joined: Sep 24, 2005

(No subject)

czvi wrote:
click menu item "Video Preview" of menu "Video" of menu bar item "Video" of menu bar 1


i would try to edit this line to read:

Code: Select all
click menu item "Video Preview" of menu "Video" of menu bar 1

it seems like there may be a typo in there. not sure.

Posted on
Wed Sep 20, 2006 5:38 am
czvi offline
Posts: 79
Joined: Jul 23, 2006

(No subject)

That did it! Funny, because the next line has the same syntax but doesn't cause an error.

I need to learn Applescript when I have time.

Posted on
Wed Sep 20, 2006 11:07 am
rustbuster2 offline
Posts: 21
Joined: Feb 24, 2006
Location: Gatineau, QC Canada

(No subject)

macpro wrote:
rustbuster2 wrote:
Does anyone have any ideas on how to extend doctorlambo's script to place the pictures on the 2.0 IndigoServer control pages?

- Copy the pictures into the folder Library>Application Support>Perceptive Automation>Indigo 2>IndigoWebServer>images>controls>static
- Give them always the same name "pic1.png" ... "pic5.png"
- Make sure they are saved in ".png" format


IChat saves snapshots in tiff. Do you know how I could convert tiff to png?
MikeL

Posted on
Wed Sep 20, 2006 11:56 am
Otis offline
Posts: 210
Joined: Jan 24, 2006

(No subject)

rustbuster2 asked:

IChat saves snapshots in tiff. Do you know how I could convert tiff to png?


Open the file in Preview and do a Save As, choosing the PNG format. Haven't tried it, but it should work.

Posted on
Wed Sep 20, 2006 12:40 pm
rustbuster2 offline
Posts: 21
Joined: Feb 24, 2006
Location: Gatineau, QC Canada

(No subject)

Thanks for the suggestion. Preview doesn't appear to be scriptable but good old Graphic Converter is. I think I can tell GC to open the TIFF file from iChat and then Save As PNG to the IndigoServer directory. I want to use Applescript to do this so that the iSight pictures get placed automatically onto the Indigo Control Page.
MikeL

Cheers,
Mike L

Posted on
Tue Sep 26, 2006 8:03 pm
rustbuster2 offline
Posts: 21
Joined: Feb 24, 2006
Location: Gatineau, QC Canada

(No subject)

Code: Select all
(*
Inspired by the cool script created by Ian Dopps (posted Dec 22, 2005) I thought I'd try writing a script that didn't rely on iChat or System Events to interact with the iSight camera. So here goes.
--
This script captures a still image using the Indigo 2.0 server's iSight camera and places the image on the Web Server control page.
The script uses Alex Bauer's isightcapture CLI utility to acquire and process the image (see http://www.intergalactic.de/hacks.html)
and is attached to a button on the control page labelled "Update Image". The image is placed on the page as a static image
referencing the file pic2.png in the static images folder. Note, the web page image does not automatically update when the image file changes (Indigo 2.0 beta 2) but maybe Matt will fix this. I've also used a Variable Value object on the control page as a caption for the image. This references a variable defined in Indigo ("cp2" in the script). Fortunately, this does change on the web page when it's updated by the script.
--Mike Lussier Sep 26, 2006
*)

set cp to "cp2" --control page image caption (Indigo variable)
set imageFileName to "pic2.png"
set imageTitle to "View from MB Balcony"

set sd to path to startup disk as text
set IndigoWebServerPath to (sd & "Library:Application Support:Perceptive Automation:Indigo 2:IndigoWebServer:")
set staticImagesFolder to (IndigoWebServerPath & "images:controls:static:")

set the value of variable cp to "Processing new image..."
do shell script "/Applications/isightcapture -n 10 -t png -w 160 -h 120 ~/Desktop/" & imageFileName
delay 2
tell application "Finder"
    set imageFile to (first file of desktop whose name is imageFileName)
    set modDate to modification date of (imageFile)
    move imageFile to folder staticImagesFolder with replacing
end tell

--update the image caption and Indigo log
set the value of variable cp to (imageTitle & " on " & weekday of modDate & ", at " & text from word 5 to word 6 of (modDate as text) & " " & word 8 of (modDate as text))
log "Updated image " & imageTitle & " (Indigo Web Server)"

Cheers,
Mike L

Posted on
Wed Sep 27, 2006 8:48 am
czvi offline
Posts: 79
Joined: Jul 23, 2006

(No subject)

rustbuster2 wrote:
Code: Select all

set the value of variable cp to "Processing new image..."

set the value of variable cp to ...


Thanks! Works great. I do get a syntax error on the above two lines,
so I commented them out.

Posted on
Wed Sep 27, 2006 9:23 am
rustbuster2 offline
Posts: 21
Joined: Feb 24, 2006
Location: Gatineau, QC Canada

(No subject)

czvi wrote:
rustbuster2 wrote:
Code: Select all

set the value of variable cp to "Processing new image..."

set the value of variable cp to ...


Thanks! Works great. I do get a syntax error on the above two lines,
so I commented them out.


In the script cp is set to "cp2". cp2 is the name of a variable in Indigo that holds the caption for the image on my web control page. You need to add this variable to your Indigo Variable List and then refer to it on your web control page. I set it up this way so that I could place several video images on the control page each with their own captions. I planned to use a list to relate the image file, the Indigo variable, and the image name, in the form:
{"pic1.png", "cp1", "View from Front Door", "pic2.png", "cp2", "View from MB Balcony", etc}
and just iterate over the list to set the script variables. But, I didn't do that in my example script because I only have one iSight and I'm not sure how I'd get images from multiple cameras, in any case. Hope this explanation is useful.

Cheers,
Mike L

Posted on
Wed Sep 27, 2006 2:06 pm
macpro offline
User avatar
Posts: 765
Joined: Dec 29, 2005
Location: Third byte on the right

(No subject)

Great script! I'll give it a try this weekend.
One question: does the iSight remain on all the time?
Or does it switch off between taking two pictures?

Who is online

Users browsing this forum: No registered users and 10 guests