I also want to add that this works with AppleScript records, allowing
you to pass in a even more complex data. AppleScript records are like
lists, except the items can be named and reference by the AppleScript:
set x to {name:"John", hamburger:"well-done"}
So that in Applescript you can say:
name of x --returns "John"
The string version of the record is coerced the same way as the
string lists in my last message.
Your REALbasic program should create a string that encapsulates your
data with named values and pass it to your AppleScript as a string:
MsgBox RecordParam(myRecordString)
Your applescript can then coerce the string and reference the record
values by name:
on run {paramString}
--{name:"John", hamburger:"well-done"}
set paramRecord to run script (paramString)
return name of paramRecord
end run
The returned value is "John"
John Balestrieri
Tinrocket, LLC
www.tinrocket.com
On Jan 19, 2007, at 5:09 PM, John Balestrieri wrote:
I just wanted to pass along this tip for calling AppleScript from
REALbasic programs:
REALbasic lets you pass strings to an AppleScript, but sometimes
you need to pass more complex data, such as a tree object or even a
simple list. AppleScript supports list objects for this type of
data, and you can coerce a string to a simple list:
set x to "{10,{20,30}}" as list --produces a list with one item:
the original string
but there is no well-documented or obvious way to coerce the above
string list to a real list and restore all the original items and
sub-items.
The trick is to parse the string list with the run script
AppleScript command:
set x to "{10,{20,30}}"
set y to run script (x) --y is now a hierarchical AppleScript list
To use this in an AppleScript called from REALbasic, just perform
run script command on the run handler's parameter; the one you'll
provide from your REALbasic app:
on run {paramString}
set paramList to run script (paramString)
...
and from REALbasic, pass in your data as list string:
MyAppleScript("{10, {20, 30}}")
When this AppleScript:
on run {paramString}
set paramList to run script (paramString)
return item 1 of item 2 of paramList
end run
is called from REALbasic:
MsgBox MyAppleScript("{10, {20, 30}}")
The returned value is "20", the nested value we passed in.
John Balestrieri
Tinrocket, LLC
www.tinrocket.com
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>