Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

[Mac] AppleScript XML-RPC

Xero Zaius
Registered User
Join date: 4 Jan 2004
Posts: 17
08-25-2005 19:01
I put together a little AppleScript to send messages to objects in SL.

CODE
(* Prepare the data to send *)
set rpcData to {|Channel|:"c6b4e874-a1a7-0a07-6914-2db3bc911eeb", |StringValue|:"Hello cube!", |IntValue|:0} as record

(* Now we tell the CGI application... *)
tell application "http://xmlrpc.secondlife.com/cgi-bin/xmlrpc.cgi"
(* To call the remote procedure *)
set returnValue to call xmlrpc {method name:"llRemoteData", parameters:{rpcData}}
end tell


Something pretty sweet about this is you can also write a script to watch iTunes and send the name of the currently playing song the object.

returnValue is a record, so to get the string value you have to say
CODE
set returnedString to the StringValue of returnValue


edit: Fixed an error
edit2: Fixed another error and added a note

-XZ
Jesrad Seraph
Nonsense
Join date: 11 Dec 2004
Posts: 1,463
08-26-2005 02:01
That's so cute :) Much easier for a quick Terminal task or cron job than a Perl script.

But how do I get data back from the object's RPC response ?
_____________________
Either Man can enjoy universal freedom, or Man cannot. If it is possible then everyone can act freely if they don't stop anyone else from doing same. If it is not possible, then conflict will arise anyway so punch those that try to stop you. In conclusion the only strategy that wins in all cases is that of doing what you want against all adversity, as long as you respect that right in others.
Merwan Marker
Booring...
Join date: 28 Jan 2004
Posts: 4,706
08-26-2005 05:50
Thanks Xero!


:)
_____________________
Don't Worry, Be Happy - Meher Baba
Jesrad Seraph
Nonsense
Join date: 11 Dec 2004
Posts: 1,463
08-26-2005 09:03
I've found some useful info there: http://developer.apple.com/documentation/AppleScript/Conceptual/soapXMLRPC/chapter2/chapter_2_section_3.html

I've reworked your script a bit so it returns whatever answer the scripted object sends back:

CODE

(* Prepare the data to send *)
set rpcData to {|Channel|:"c6b4e874-a1a7-0a07-6914-2db3bc911eeb", |StringValue|:"Hello cube!", |IntValue|:0} as record

(* Now we tell the CGI application... *)
tell application "http://xmlrpc.secondlife.com/cgi-bin/xmlrpc.cgi"
(* To call the remote procedure *)
set returnValue to call xmlrpc {method name:"llRemoteData", parameters:{rpcData}}
end tell
return returnValue


Does it work ? I cant test it right now and it's my first AppleScript.
_____________________
Either Man can enjoy universal freedom, or Man cannot. If it is possible then everyone can act freely if they don't stop anyone else from doing same. If it is not possible, then conflict will arise anyway so punch those that try to stop you. In conclusion the only strategy that wins in all cases is that of doing what you want against all adversity, as long as you respect that right in others.
Xero Zaius
Registered User
Join date: 4 Jan 2004
Posts: 17
08-26-2005 13:19
Yea, that works. I just forgot to put that in when I fixed up the script. I'll edit my post up top if it will still let me and fix it :)

Another note is that it returns a record when you're done, so to get the returned string you need to

CODE
set theReturnedString to StringValue of returnValue


-XZ
Drkmirror Plasma
Registered User
Join date: 25 Jan 2006
Posts: 3
04-19-2006 00:36
Thank you thank you.
you just saved me a lot of work
Lallander Parvenu
Registered User
Join date: 21 Apr 2005
Posts: 45
04-19-2006 09:26
Could you perhaps post an example of how to interact with another app like iTunes?
I have never actually messed around with applescript before.
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
04-19-2006 11:41
You can also run Applescripts straight from the shell, using the "osascript" command. I do that to run an applescript from my Powermate because the Powermate driver has no way to directly call Applescripts other than the ones they use internally.

Pity you can't initiate XMLRPC calls from SL, or I'd make a HUD that controlled iTunes.
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
04-19-2006 11:43
From: Lallander Parvenu
Could you perhaps post an example of how to interact with another app like iTunes?
Try Doug's Applescripts for iTunes.
Lallander Parvenu
Registered User
Join date: 21 Apr 2005
Posts: 45
04-19-2006 11:50
I meant from within SL.
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
04-19-2006 13:37
From: Lallander Parvenu
I meant from within SL.
You can't initiate XMLRPC from within SL (as I noted in my other message), so what you need to so is to have iTunes (using Doug's scripts, perhaps, for the basis of the iTunes side) send updates to the prim containing your LSL script, and have the prim send commands and requests back in the response.
Lallander Parvenu
Registered User
Join date: 21 Apr 2005
Posts: 45
04-19-2006 18:25
Well aware of that, the question was if someone could post an example of a LSL/applescript combo that will allow you to control an application from the host machine. I have absolutely no experience with applescript, and was wondering how other people would get around the fact that you can't request data from within SL. I've heard some people kick off the initial data request with an email.
Nicola Escher
512 by 512
Join date: 1 May 2003
Posts: 200
04-20-2006 17:28
Cocoa XML-RPC Client

Nice little client for testing XML-RPC from OS X. Have fun!
_____________________
NicolaEscher.com
Tutorials, fashion, and photos.
Tuber Potato
Registered User
Join date: 26 Jan 2006
Posts: 57
09-02-2006 07:37
Could someone possibly paste both the AppleScript and the LSL Script?

The AppleScript that sends the Song Data to SL and the LSL Script that recieves the Song Data and displays it?

This would be very helpful as I am unsure how to edit the AppleScript to do that.

Thanks
Tuber Potato