Page 1 of 1

From lua to AppleScript

PostPosted: Sat Feb 14, 2015 2:29 pm
by davinci
I want to use this code in AppleScript to control my TV.

Code: Select all
TV = Net.FHttp("192.168.1.6",1925)
jsonString = {id="hdmi1"}
jsonTable = json.encode(jsonString)
response, status, errorCode = TV:POST("/1/sources/current?callback=", jsonTable )


Is there a guide for how to do this? If I just use curl and try to post the jsonString it gives back "bad argument".

Re: From lua to AppleScript

PostPosted: Mon Feb 16, 2015 6:13 pm
by jay (support)
AppleScript isn't very well suited to this task. Python, however, is quite good at both HTTP and JSON.

I'm unclear from your example exactly what's happening though: it looks like you're doing a POST of some JSON data to a url that looks incomplete ("http://192.168.1.6:1925/1/sources/current?callback="). I don't know LUA so I can't really translate. If you can describe exactly what the communication looks like then we can probably figure out the right Python.

Re: From lua to AppleScript

PostPosted: Mon Feb 23, 2015 11:55 am
by davinci
I'm basically doing this:
http://jointspace.sourceforge.net/proje ... c/API.html

Thanks for further help. I'm now getting into Python. :)

Re: From lua to AppleScript

PostPosted: Mon Feb 23, 2015 10:04 pm
by jay (support)
Yep, that should be quite straight-forward in Python. I highly recommend finding one of the many Python tutorials out on the net and just working your through it. It won't take long and will give you a much better base of understanding before trying to tackle something more complex.

Re: From lua to AppleScript

PostPosted: Tue Feb 24, 2015 5:00 am
by davinci
I'm doing this learning by doing. But something like this has been done before, so I'm actually looking forward to a code snippet from somebody who does this already.

Re: From lua to AppleScript

PostPosted: Tue Feb 24, 2015 11:14 am
by BassMint
Try putting together the url and test it in your browser. If it gives the right response, then use curl in an shell script or applescript

i.e.

Code: Select all
#!/bin/sh
curl "http://192.168.1.6:1925/1/sources/current?callback=(whatever this is)"


Like Jay said, the url appears incomplete as there should be something after the "="
I learn like you, trial and error, copy and paste.
I am just taking a stab as I really don't know....

in applescript it would be something like:

Code: Select all
do shell script "curl 'http//192.168.1.6:1925/1/sources/current?callback=(whatever this is)'"

Re: From lua to AppleScript

PostPosted: Wed Feb 25, 2015 9:32 am
by davinci
Thanks.

It is all described here:
http://jointspace.sourceforge.net/proje ... -POST.html


For someone like jay an easy task I guess. What do you think?