send param with shell osa script

Hi everybody… again :expressionless:
I’v learned here by Michel Bujardet
how activate applescript by shell s.execute("osascript " + filez.ShellPath)
i even able to catch a return string by s.result
But i can’t send string ( param )
I’v tried s.write("test")… or s.writeline("test")… No ain’t work
Thanks to help me for that little step

I’ve googled for “osascript parameter” and got some rather painfull links like http://stackoverflow.com/questions/17242773/pass-in-variable-from-shell-script-to-applescript

I’d use this only in emergencies. What are you trying to do? Why can’t you generate your scripts in Xojo code?

Yes Beatrix… i’v googled everyWhere i could to find myself :slight_smile:
I use applescript to make UI scripting to acces windows that is not reachable by basic applescript
First i catch ALL the SaveAs -optimized drop down item
Return it to xojo to select the item
then re-call another applescript UI to apply Save As Optimized PDF with the (xojo)selected choice
I’d doubt that can be donne all in xojo app ( UI scripting )

I recommend to look into Proper way to execute an AppleScript?. No need to use osascript at all…

He is using RS2012 and for some reason Notification does not work when an AppleScript is dragged into the project. That is why.
I verified so myself with 2012R1.2. I can’t remember at the moment when notifications were introduced. Maybe after 2012 ?

@Denis Despres : I just tried myself with my own notifications script. Place the parameters between quotes after the script. The double quotes let you enter quotes into a string. What the script receives is "Hello world" "Nice day is it not ?"

dim s as new shell dim f as folderitem = specialfolder.desktop.child("notifications.scpt") s.execute("osascript "+f.shellpath+" ""Hello world"" ""Nice day is it not ?""")

From that thread, I’m using this method: https://forum.xojo.com/10609-proper-way-to-execute-an-applescript/p2#p76162
Works good with small(er) scripts that are finished quickly like notifications or asking finder something.
Longer running AppleScripts will block the main thread though. Even when submitted from a thread. (But I think that’s also the case for scripts that were dragged in.)
For that, it’s better to do async shells to osascript.

just found a date for Notification. It appears Applescript became able to display notifications with Mavericks. That would be the end of 2013, so it makes sense the implementation in RS2012 would not be able to do it.

For myself, the notifications.scpt script has been a good tool for years. I drag it in the project because that way it takes the icon from the app.

Thank’s EveryOne
I’ll check every Way… I’m in learning process
@Marco Hof : It gone take time to understand… but i will try
@Michel Bujardet : Yes Michel it work well… The notification Too !!

ooops!
How can i send string variable instead raw text in quote

If you drop in the function ExecuteAppleScript, you can run AppleScript that launches a notification something like this:

Dim title As String = "A Title"
Dim message As String = "The Message"
Dim subMessage As String = "The Sub Message"
Dim sound As String = "Purr"

asScript = "display notification """ + subMessage + """ with title """ + title + """ subtitle """ + message + """ sound name """ + sound + """" + EndOfLine
      
Call ExecuteAppleScript(asScript)

You just construct the AppleScript into a string. So above, aScript is the AppleScript for a notification.

Thanks Marco
I’v already done everything with drag applescript to RS…send param et get return
I’v switch to Shell script because i use UI script inside my applescript
and it seem more stable to keep pref of “Enable access for assistive devices” for my app

With variables :

dim s as new shell dim f as folderitem = specialfolder.desktop.child("notifications.scpt") dim title as string = "Hello world" dim msg as string = "Nice day is it not ?" s.execute("osascript " + f.shellpath + " " + title + " " + msg)

Merci !!!