Apple Script and IP Cameras - How To

Posted on
Thu Jan 28, 2016 10:15 am
whmoorejr offline
User avatar
Posts: 762
Joined: Jan 15, 2013
Location: Houston, TX

Apple Script and IP Cameras - How To

Ever since Foscam went to the newer HD models, I've been having issues with getting images for emails, text messages, etc.... I finally got it figured out so I thought I'd share...

Dynamic Control Page Image:

Create a folder on the desktop of the computer running indigo called "IPCamRotate"
Set up a trigger (motion, door, etc, ) to then run the following script:
(Change URL to URL of your camera and use your userID and Password.)
Code: Select all
do shell script "curl -f 'http://10.0.6.181:8081/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=userid&pwd=password' -o ~/Desktop/IPCamRotate/R.jpg"


To flip through a couple different camera images on a triggered event, use:
Code: Select all
do shell script "curl -f 'http://10.0.6.183:8083/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=userid&pwd=mypassword' -o ~/Desktop/IPCamRotate/R.jpg"
delay 2
do shell script "curl -f 'http://10.0.6.181:8081/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=userid&pwd=mypassword' -o ~/Desktop/IPCamRotate/R.jpg"
delay 2
do shell script "curl -f 'http://10.0.6.183:8083/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=userid&pwd=mypassword' -o ~/Desktop/IPCamRotate/R.jpg"


On a control page:
Create a Refreshing Image URL and use the following:
file:///Users/williammoore/Desktop/IPCamRotate/R.jpg (Change my name to the username running your indigo server)
Refresh rate set to continuous. As whatever trigger takes whatever picture, that "R.jpg" will change and be displayed in the control page.

My image takes up a big chunk of the screen. I have also set the Client Action to go to my main automation page for lighting control, etc. My house iPads are running a Kiosk program to view indigo control pages..... so after 20 seconds or so of inactivity, it automatically flips back to the home page (with the refreshing camera rotating dynamic thingie).


Take snapshot and send via iMessages:
Change the following:
URL: Use address of your camera, use your username and password
Folder path: change from my name "williammoore" to the user name your indigo server is running under.
Buddy: use the email address(s) associated with your apple ID, your wife's apple ID, etc.

Code: Select all
set dFolder to "~/Desktop/IPCam/"

do shell script "mkdir -p " & dFolder
do shell script "curl -f 'http://10.0.6.181:8081/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=username&pwd=password' -o ~/Desktop/IPCam/1.jpg"
delay 2

tell application "Finder"
   set folderPath to folder "Macintosh HD:Users:williammoore:Desktop:IPCam"
   set theFile to first file in folderPath as alias
   set fileName to name of theFile
end tell
set theAttachment1 to theFile

tell application "Messages"
   send theAttachment1 to buddy "myname@gmail.com" of (service 1 whose service type is iMessage)
   send theAttachment1 to buddy "mywife@gmail.com" of (service 1 whose service type is iMessage)
end tell

delay 2
tell application "Finder"
   delete folder "IPCam"
end tell


Take snapshot and send via Email:

Code: Select all
set dFolder to "~/Desktop/IPCam/"

do shell script "mkdir -p " & dFolder
do shell script "curl -f 'http://10.0.6.181:8081/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=username&pwd=password' -o ~/Desktop/IPCam/1.jpg"
delay 2

tell application "Finder"
   set folderPath to folder "Macintosh HD:Users:williammoore:Desktop:IPCam"
   set theFile to first file in folderPath as alias
   set fileName to name of theFile
end tell
set theAttachment1 to theFile

tell application "Mail"
   set addressList to {"myhome@gmail.com", "mywork@hq.dhs.gov","wifehome@gmail.com"}
   set nameList to {"billgmail", "millwork","wifehome"}
   
   set newMessage to make new outgoing message with properties {subject:"Front Door", content:"Attached Image" & return & return}
   
   tell newMessage
      
      set visible to false
      set sender to "myaccount@gmail.com"
      repeat with i from 1 to count nameList
         make new to recipient at end of to recipients with properties {name:item i of nameList, address:item i of addressList}
      end repeat
      make new attachment with properties {file name:theAttachment1} at after the last paragraph
      send --<<<<---------------- change save to send to send
      (* change save to send to send*)
      
   end tell
end tell
delay 2
tell application "Finder"
   delete folder "IPCam"
end tell


I don't know if it's necessary to delete the folder in the last two scripts. I had a problem in the past with the previous curl command not wanting to overwrite the file. The curl command I'm using now seems to overwrite it fine.... so it might be an unnecessary step.... but it ain't broke, so I ain't fix'n it.
I hope this is helpful for some folks.

Bill
My Plugin: My People

Posted on
Thu Jan 28, 2016 1:19 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Apple Script and IP Cameras - How To

Thanks for the information, I'm sure others will find it useful.

[MODERATOR NOTE] moved to the AppleScript forum.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Jan 29, 2016 8:15 am
jalves offline
Posts: 744
Joined: Jun 16, 2013

Re: Apple Script and IP Cameras - How To

Appreciate the info. I'm spending some time working over my control pages and one of the things I wanted to do was to incorporate some images from my Foscam cameras. This will let me make one that shows an image of my garage on the same page where I control the light and the garage door opener.

Running Indigo 2023.2 on a 24" iMac M1), OS X 14.4
Jeff

Posted on
Mon Mar 14, 2016 9:34 am
jalves offline
Posts: 744
Joined: Jun 16, 2013

Re: Apple Script and IP Cameras - How To

Just getting around to playing with this and got a basic control screen working. Thanks!

Note to others that want to do this, be sure you have both the URL and the port number correct for your camera.

Running Indigo 2023.2 on a 24" iMac M1), OS X 14.4
Jeff

Posted on
Mon Mar 14, 2016 9:53 am
whmoorejr offline
User avatar
Posts: 762
Joined: Jan 15, 2013
Location: Houston, TX

Re: Apple Script and IP Cameras - How To

My home based control pages tie in with ip cameras so I can watch lights turn on/off. Garage door open / close... etc.

My away control pages are more text based so I use some of the script stuff to email or text a picture confirmation when I close the garage door, my office door opens, etc. (I still get visual confirmation without sucking up reflector bandwidth).

It would be a nice feature if we could export and import control pages and such with others.

Bill
My Plugin: My People

Posted on
Mon Mar 21, 2016 3:06 am
MaartenT offline
Posts: 20
Joined: Jan 12, 2015

Re: Apple Script and IP Cameras - How To

Take snapshot and send via iMessages


Great.. It works!!.

is there a simple line of code to change the jpg size to 25% or 50%

in my situation the jpg is about 500kb

Posted on
Mon Mar 21, 2016 9:08 am
whmoorejr offline
User avatar
Posts: 762
Joined: Jan 15, 2013
Location: Houston, TX

Re: Apple Script and IP Cameras - How To

Yes/sorta.... I suck at applescript.... this is just a result of me googling and trying a couple things.... but I think I have 4 answers for you:

download this.... it will be helpful for other stuff too.... http://www.dashony.com/files/Foscam%20IPCamera%20CGI%20User%20Guide-V1.0.4.pdf

1) On the camera web interface, you should be able to adjust the resolution of the image snaps. (Settings --> Video --> Snapshot Settings --> Snap Quality )

2) Your camera may be able to snap a picture and change the resolution of the snapped picture (Mine don't do this)...
Code: Select all
do shell script "curl -f 'http://10.0.6.181:8081/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=userid&pwd=password&resolution=32' -o ~/Desktop/new.jpg"
adding resolution to the code above (This didn't work for me)


3) use a shell script to change the camera settings in your applescript code (add all three lines together):

change image to "low" quality:
Code: Select all
/cgi-bin/CGIProxy.fcgi?cmd=setSnapConfig&snapPicQuality=0


grab the image:
Code: Select all
do shell script "curl -f 'http://10.0.6.181:8081/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=userid&pwd=password' -o ~/Desktop/new.jpg"


change back to "high" quality:
Code: Select all
/cgi-bin/CGIProxy.fcgi?cmd=setSnapConfig&snapPicQuality=2


4) Manipulate the image after you grab it.... add this line to the applescript directly after the shell script that snaps the picture:
Code: Select all
tell application "Finder"
   set this_item to get selection
   set myPath to POSIX path of (this_item as text)
end tell
tell application "Image Events"
   set this_image to open myPath
   scale this_image to size 500
   save this_image in myPath
   close this_image
end tell
<-- adjusting the size "500" will adjust the pixel width of the image and therefore adjust the size of the saved image.

Hope this is helpful.

Bill
My Plugin: My People

Posted on
Mon Mar 21, 2016 9:19 am
MaartenT offline
Posts: 20
Joined: Jan 12, 2015

Re: Apple Script and IP Cameras - How To

Cool.. Thanks.
i'll give it a shot.

I was already looking at the settings of the cam if it was possible to lower the picture quality. Otherwise i'll try the additional tool.

Thanks!!

Posted on
Tue Nov 08, 2016 3:19 pm
jalves offline
Posts: 744
Joined: Jun 16, 2013

Re: Apple Script and IP Cameras - How To

Sorry to resurrect an old thread but I found this very helpful with my Foscam Cameras. I've since purchased a couple of Amcrest cameras and was hoping the same code would work on them. I found the Amcrest API on line but my knowledge of AppleScript/Curl and or the correct syntax seems to be lacking. Anybody got an Amcrest camera that has adapted this script to work for them?

Running Indigo 2023.2 on a 24" iMac M1), OS X 14.4
Jeff

Posted on
Tue Nov 08, 2016 7:05 pm
whmoorejr offline
User avatar
Posts: 762
Joined: Jan 15, 2013
Location: Houston, TX

Re: Apple Script and IP Cameras - How To

I still suck at this and have my fingers crossed for a good NVR plugin when Indigo7 is release so I can stop playing with applescript....

To the point, the only thing that should change from the script to adapt to a different camera should be the URL for a JPG. The part above if it was working for your Foscam cameras, I would imagine you would keep the
Code: Select all
do shell script "curl -f '
and the
Code: Select all
-o ~/Desktop/IPCam/1.jpg"
just replace the URL in the middle between the single quotes with one that captures an image.

result:
Code: Select all
do shell script "curl -f 'http://URL.CGI Syntax for my new amcrest camera to get a snapshot .jpg file' -o ~/Desktop/IPCam/1.jpg"


Unfortunately, I'm waiting for Indigo 7 before making any more big investment changes to my current set up. Amcrest and Foscam are made by the same guys (the are in the same building) so I would think it would work just fine.

Bill
My Plugin: My People

Posted on
Fri Dec 02, 2016 8:09 pm
bkmar1192 offline
Posts: 274
Joined: Sep 12, 2015

Re: Apple Script and IP Cameras - How To

You can check out my new security camera plugin here (if you know the image URL it should work).: Bert's Plugins

https://r.tapatalk.com/shareLink?url=ht ... re_type=sf


Sent from my iPhone using Tapatalk

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests