Help with Home Automation Project?

[b]I am trying to write a applescript for a interactive iPhone doorbell camera
(Here is a demo)
http://www.youtube.com/watch?v=ZJQeecOJUFs

I have it, when it launches the script, it calls my iPhone via facetime
if I doesn’t answer after 35 seconds, it disconnects and quits facetime and ends the program
if I do answer the call it keeps the connection active (I can’t figure out how to make it watch for inactivity and quit facetime, but the program still quits)

ultimately I would like the program to be able to call me, when its triggered, but also wait for a call so if I miss the call I can ‘call it back’[/b]

Here is the code I have so far

open location “facetime://12345678”
delay 5
– simulate pressing the Enter key
tell application “System Events”
keystroke return
– Check to see if Facetime is active
tell application “System Events” to set theCount to the count of (processes whose name is “Facetime”)
if theCount = 0 then
do shell script “sleep 1”
else
tell application “FaceTime” to activate
– sets how long facetime will ring your phone (40 secs)
do shell script “sleep 40”
tell application “FaceTime” to activate
tell application “System Events” to tell process “FaceTime”
if name of front window contains “with” then
do shell script “sleep 1”
– if call is active wait 60 seconds before rechecking
else
– Check to see if call is still active
tell application “System Events” to tell process “FaceTime”
if name of front window contains “with” then
do shell script “sleep 1”
else
– Quit Facetime if call is not active
if name of front window contains “facetime” then
tell application “FaceTime” to quit
do shell script “sleep 1”
end if
end if
end tell
end if
end tell
end if
end tell

Here is a program that will 'watch the connection and auto answer incoming face time requests:

– Facetime Auto Answer
– Copyright ©2010 CornDog Computers
– twitter: @CornDoggyRob

repeat
– Check to see if Facetime is active
tell application “System Events” to set theCount to the count of (processes whose name is “Facetime”)
if theCount = 0 then
do shell script “sleep 1”
else
tell application “FaceTime” to activate
do shell script “sleep 2”
tell application “FaceTime” to activate
tell application “System Events” to tell process “FaceTime”
if name of front window contains “with” then
do shell script “sleep 5”
else
tell application “System Events” to activate application “FaceTime”
keystroke return
do shell script “sleep 5”
– Check to see if call is active
tell application “System Events” to tell process “FaceTime”
if name of front window contains “with” then
do shell script “sleep 5”
else
– Quit Facetime if call is not active
tell application “FaceTime” to quit
do shell script “sleep 5”
end if
end tell
end if
end tell
end if
end repeat
end

[b]
Anyone have any ideas?

Thanks!

Jonathan[/b]

Maybe check to see if the face time window contains “ended”? Also, I would advise having the two separate scripts running in separate windows (not sure if thats what you’re doing now) and believe there is a way for them to communicate, worst case scenario you could use a textedit doc for them to connect.

Thanks for the reply, I was able to tweak the program a bit and with something I found on the internet I was able to remove the auto answer applescript completely from the mix (here is the hint)
[i]
Nice auto-answer facetime hack

Dunno if it's been posted yet, but the facetime app for OS X allows you to 'auto answer' facetime calls with whitelisting phone numbers, apple ID's or allowing anyone.

to allow a single mobile, open terminal and type:

defaults write com.apple.FaceTime AutoAcceptInvitesFrom -array-add +15205551212

(where the number on the end is your iPhone)

It will activate facetime, even if its not open.[/i]

I am still having problems with the applescript seeing when the call ends, and quitting facetime

Jonathan

It took me almost a week to figure out all the bugs, (Kudo’s to you programmers, I always thought I was pretty smart, but after this week I feel dumber then a rock on Jerry Springer)

The Final Product does this.

When a Arduino is activated (with a relay) it starts the applescript on a Host mac mini with a camera/mic/speaker
The applescript starts a Facetime session with my cell phone
The applescript initiates a AUTOMATOR session, that does a video capture of the Host camera, and emails it to me (photo)
The Applescript Starts a Quicktime Movie capture of the Host camera
The Applescript waits for the Facetime session to disconnect
when it sees no Facetime activity it records an additional 15 seconds of video, closes the file
quits facetime
and ends the program again, ready to be re-started by the Arduino

Once the project is working, I will post a youtube video of it

Thanks again

Jonathan