applescript passing var to xojo

Hi everybody
I’m passing data from xojo to applescript then place it to a website via safari with document.getElementById…
It work very well
I’m wondering if i can get some data from applescript to xojo before the function to throw it to website
Thanks

How are you using the applescript? Is it a script file that you drag into the navigator? If so you can do something like this in an applescipt:

on run {parameters}
//do some stuff 
set theResult to _______
return theResult //<- returns theResult to xojo
end run

Then in your project you can do:

dim applescriptResult as SOMETYPE = theApplescript(parameters)

If you are executing it from a shell then you can do:

dim s as new shell
s.execute "osascript " + FOLDERITEMTOAPPLESCRIPT.shellpath
dim result as string = s.result //<- the result of the applescript

Does that make sense?

I drag my applescript in IDE
Must something i don’t catch
i must dim my var (X) in xojo first… because it dont recognize it
then include it in my parameter? to applescript
In applescript…give the data to var…then return
and in xojo i should re-dim another var (Y) with the return var(X) in applescript(X)
At he end both var are empty!!!
The logic is there…but what i’v missed?
Thanks

You’re on the wrong track.

If you are looking to pass information FROM an AppleScript TO Xojo, you must implement the App.HandleAppleEvent handler, and you may have to create an AppleScript dictionary for your application so it can be scripted.

If you are looking to pass information FROM Xojo TO an AppleScript, that’s a lot easier. Your script will look like this:

on run(theParameters)
…
end

and in Xojo, you call it like this:

dim s as string

s=“This text will be passed to AppleScript”

theNameOfYourAppleScript(s)

Just to expand on what Eric has correctly posted, you can only communicate with Applescripts via text strings unfortunately, they would be a lot more useful on occasions if Xojo supported some of the other basic data types like numbers or boolean values, and maybe even AS lists and records, which would be Xojo arrays and dictionaries respectively, although I have converted all of those types myself with code in past projects, but does require a lot more code writing.

But in order to retrieve a result from the Applescript, you would need the script to return a text result, so Eric’s code would be more like this.

// In Xojo project

Dim theResult as String
Dim myText as String

myText = "This text will be passed to AppleScript"

theResult = theNameOfYourAppleScript(myText)

if theResult = //Check the returned result
-- In Applescript

on run{theParameter}

    --Do something with theParameter

    return aResult as text
end run

Regards Mark

Hi Mark
your example is very clear and easy…like i said… I missing something… It return empty

//In JOXO dim textfromapples as String --init my text fillformbyIDx(v01customer,v02tempname) -- run my applescript with other param textfromapples = fillformbyIDx(textfromapples) --retreive my text break ---check result

//in applescript (called fillformbyIDx) set textfromapples to "Hello World" as text --set my text display dialog textfromapples -- test in applescript return textfromapples as text --return to XOJO
Even if i include (textfromapples) in my param = same result…empty var return
thanks for your help

the full script in applescript is

on run {v01customer, v02tempname} (do something with param)) set textfromapples to "Hello World" as text --set my text display dialog textfromapples -- test in applescript return textfromapples as text --return to XOJO end run

Denis I think your totally misunderstanding the way to use AppleScript’s with Xojo.

I’m assuning by your code the AppleScript is named “fillformbyIDx” in the Xojo project browser, is this correct ?

If the answer to the above quetion is yes, then this line in your code.

[code]fillformbyIDx(v01customer,v02tempname) – run my applescript with other param/code]
Is calling the Applescript with two unkown values, and is not going to give you a return value.

What are the “v01customer” and “v02tempname” variables values, and their data types ?

Also the next line in your code example, this one here.

 textfromapples = fillformbyIDx(textfromapples)      --retreive my text

will also not return a value from the script.
Because your passing one empty string parameter to the script, but the script is expecting two parameters.

Which means the script is not running through to it’s end, and in fact is having an internal error, which your
unaware of, because you Xojo App cannot trap internal errors in the Applescript itself.

What I suggest is, try expaining exactly what your trying to achieve, then I can perhaps show you how to do it.

Regards Mark

Denis I’ve quickly put together a simple Xojo project, to show the concept of using Applescript’s in your own projects.

You can download it from here.
XojoNotification

I’ve included the two Applescripts in the zip file, although I’ve already included them in the Xojo project, but this will
allow you to examine the code from both sides, and if you look carefully at the code, it will start to make sense.

Regards Mark

Ohh yes Mark
Two things that i’v understand with your example
1- XOJO (collect return data) in the same command line of sending param

theScriptResult = XoJoNotification(theTitleText, theSubtitleText, theMessageText, theSoundNameText)
2-The return is a text format (not a variable)

I hope its what you want me to understand
Because now its working very well
The project is to return data to XOJO pick by ( applescript safari) from webform
Thank you