Send picture files via iMessage?

Posted on
Sat Sep 09, 2017 1:27 pm
racarter offline
User avatar
Posts: 158
Joined: Jun 18, 2016
Location: North Yorkshire, UK

Send picture files via iMessage?

Does anyone know of a Python way to send CCTV snapshot files via iMessage? Currently I do it with AppleScript, but since support for this is being withdrawn I need to change this.

I know I can use py-applescript, but a pure Python solution would be nice.

Posted on
Sat Sep 09, 2017 1:50 pm
jay (support) offline
Site Admin
User avatar
Posts: 14887
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Send picture files via iMessage?

Python has the smtplib module to send emails. The iMessage question has been asked on reddit without a clear answer.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Sep 09, 2017 1:51 pm
Different Computers offline
User avatar
Posts: 1850
Joined: Jan 02, 2016
Location: East Coast

Re: Send picture files via iMessage?

Being withdrawn? I've only heard strong admonitions from Jay and Matt to move to Python because they're uncertain what Apple is going to do with AppleScript. From what I can tell, it's still supported in High Sierra.

Also, please share these scripts.

SmartThings refugee, so happy to be on Indigo. 10.13.6 on an i5 MBP w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKit Bridge, MatplotLib, Plex, uniFAP, Wunderground, Nanoleaf, LED Simple Effects, Airfoil Pro, Grafana.

Posted on
Sat Sep 09, 2017 2:05 pm
jay (support) offline
Site Admin
User avatar
Posts: 14887
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Send picture files via iMessage?

Different Computers wrote:
Being withdrawn? I've only heard strong admonitions from Jay and Matt to move to Python because they're uncertain what Apple is going to do with AppleScript. From what I can tell, it's still supported in High Sierra.


viewtopic.php?f=4&t=19013

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Sep 09, 2017 3:10 pm
racarter offline
User avatar
Posts: 158
Joined: Jun 18, 2016
Location: North Yorkshire, UK

Re: Send picture files via iMessage?

@Different Computers

Here's one of my AppleScripts. When the doorbell rings I run a Python script to grab three CCTV snapshots 5 seconds apart, then run this script to send the images via Messages.

Code: Select all
set theAttachment1 to POSIX file "/Snapshots/snap1.jpg"
set theAttachment2 to POSIX file "/Snapshots/snap2.jpg"
set theAttachment3 to POSIX file "/Snapshots/snap3.jpg"
tell application "Messages"
   send theAttachment1 to buddy "+441234567890" of service "E:mailaddress@mailserver.com"
   send theAttachment2 to buddy "+441234567890" of service "E:mailaddress@mailserver.com"
   send theAttachment3 to buddy "+441234567890" of service "E:mailaddress@mailserver.com"
end tell

Posted on
Sat Sep 09, 2017 3:12 pm
racarter offline
User avatar
Posts: 158
Joined: Jun 18, 2016
Location: North Yorkshire, UK

Re: Send picture files via iMessage?

Thanks Jay -I saw the Reddit discussion before I posted here. I guess it's the wrapper solution for now...

Posted on
Sat Sep 09, 2017 5:21 pm
jay (support) offline
Site Admin
User avatar
Posts: 14887
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Send picture files via iMessage?

Not sure I'd change anything on the script above since it isn't talking to Indigo...

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Sep 10, 2017 1:57 am
racarter offline
User avatar
Posts: 158
Joined: Jun 18, 2016
Location: North Yorkshire, UK

Re: Send picture files via iMessage?

The script is currently embedded in a trigger though - so I'll have to wrap it (or change it to external).

Posted on
Sun Sep 10, 2017 9:13 am
Gusten offline
Posts: 154
Joined: Dec 30, 2015
Location: Sweden, Gothenburg

Re: Send picture files via iMessage?

@racarter would you mind sharing the python script that collects the snapshots from the camera?

Posted on
Sun Sep 10, 2017 11:10 am
matt (support) offline
Site Admin
User avatar
Posts: 18735
Joined: Jan 27, 2003
Location: Texas

Re: Send picture files via iMessage?

racarter wrote:
The script is currently embedded in a trigger though - so I'll have to wrap it (or change it to external).

Yes, easiest approach would probably be to make it an external script file (via the Script Editor app). Indigo 7.2+ will be able to execute external AppleScript files. At this point we don't think we'll support embedded AppleScripts (even if they don't target Indigo Server).

Image

Posted on
Sun Sep 10, 2017 11:45 am
racarter offline
User avatar
Posts: 158
Joined: Jun 18, 2016
Location: North Yorkshire, UK

Re: Send picture files via iMessage?

Thanks Matt.


@Gusten

Here's a script which works with my Hikvision DVR. I run three such scripts at 5 second intervals when the doorbell rings or when the side gate is opened, then send the images via iMessage.

Code: Select all
import urllib2
import base64
img = "/<path to image folder>/snap1.jpg"
devIP = "<DVR IP address>"
username = "<DVR user name>"
password = "<DVR password>"
request = urllib2.Request("http://%s/PSIA/Streaming/channels/101/picture" % devIP)
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)   
buffer = urllib2.urlopen(request).read()
f = open(img, 'wb')
f.write(buffer)
f.close()
Last edited by racarter on Tue Sep 12, 2017 1:29 am, edited 1 time in total.

Posted on
Mon Sep 11, 2017 11:56 pm
Gusten offline
Posts: 154
Joined: Dec 30, 2015
Location: Sweden, Gothenburg

Re: Send picture files via iMessage?

Thanx, this wont work with my camera, mayby someone can help me

I have an Axis IP camera, and the download link for an snapshot is

Code: Select all
http://192.168.213.238/jpg/image.jpg


So i tried this

Code: Select all
import urllib2
import base64
devIP = "192.168.213.238"
username = "xxxxx"
password = "xxxxx"
request = urllib2.Request("http://%s/jpg/image.jpg" % devIP)
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)   
buffer = urllib2.urlopen(request).read()
f = open(img, 'wb')
f.write(buffer)
f.close()


A get an HTTP Error 401: Unauthorized

if i change the path of the image to something wrong that do not exist i get

HTTP Error 404: Not found

so it seems like the script do go to the correct place, but is not able to log in?

If a use a browser, this way will work to se the image

Code: Select all
http://username:password@192.168.213.238/jpg/image.jpg


Can anyone figure out why this is not working?

/Martin

Posted on
Tue Sep 12, 2017 1:29 am
racarter offline
User avatar
Posts: 158
Joined: Jun 18, 2016
Location: North Yorkshire, UK

Re: Send picture files via iMessage?

@Gusten

I guess the authorisation for Axis different to Hikvision.

Try something like:

Code: Select all
base64.encodestring('%s:%s' % ('user', 'password'))[:-1]
Last edited by racarter on Tue Sep 12, 2017 4:42 am, edited 3 times in total.

Posted on
Tue Sep 12, 2017 2:35 am
Gusten offline
Posts: 154
Joined: Dec 30, 2015
Location: Sweden, Gothenburg

Re: Send picture files via iMessage?

Thanx, this didn't seems to work

Code: Select all
  Script Error                    embedded script: invalid syntax
   Script Error                    around line 5 - "buffer = urllib2.urlopen(username:password@192.168.213.238/jpg/image.jpg).read()"

Posted on
Tue Sep 12, 2017 3:46 am
racarter offline
User avatar
Posts: 158
Joined: Jun 18, 2016
Location: North Yorkshire, UK

Re: Send picture files via iMessage?

Working blind here! I've edited the code, which should remove the syntax error.

Who is online

Users browsing this forum: No registered users and 1 guest