how best to trigger user selected AppleScripts?

Hi I am relatively new to XOJO, coming from MacOS automation, and I may be way out of date and heading in the wrong direction. Have managed to work out how to capture AppleEvents in XOJO and so modify my App’s interface and its functionality by sending it custom Applescript commands from an executed script. My question is related to launching Applescripts that are selected by the user in the XOJO app at runtime (so are not known in advance in the code). After saving the ShellPath of the Applescript selected by the user in a GetOpenFolderItem dialog, I run the osascript command in sh.execute function like follows:

ffpath = ff.ShellPath
sh.execute ("osascript " + ffpath)

Is this the best way to communicate between XOJO and AppleScripts, given that using ff.Launch will just open up a script in Script Editor and not actually execute it. I’m guessing that even though OSAScripting is old hat and out of date, there’s no other way or better way?

Did you read:

I have a wrapper for my AppleScript stuff available at . It’s called RunAS and I use it in my app to create about 80-90 AppleScripts on the fly. Needs the MBS plugin, though. And I still need to make the version for Mojave available.

See Speak Command for an example how to use NSAppleScript class via declare. No expensive plugin needed.

Thanks Thomas

Hi, continuing on a little, I have the code (below) to execute text ( the contents of file read into a TextArea) as an applescript. Yay, works beautifully! However, I can only do a binary read of a text file and not a compiled AppleScript file ( which just imports gibberish). It would be INSANELY GREAT if I could directly read in the compiled applescript rather than get users to resave their applescripts to text format first and then read in the plain text. What I’m looking for in addition then is maybe the reverse of the following function: rather than write text as applescript, to read compiled applescript into a textArea as plain text.

[code]soft declare function NSClassFromString lib “Cocoa” (classname as CFStringRef) as ptr
soft declare function initWithSource lib “Cocoa” selector “initWithSource:” (obj as ptr,source as CFStringRef) as ptr
soft declare function executeAndReturnError lib “Cocoa” selector “executeAndReturnError:” (obj as ptr,byref error as ptr) as ptr
soft declare function alloc lib “Cocoa” selector “alloc” (classRef as Ptr) as Ptr
soft declare function stringValue lib “Cocoa” selector “stringValue” (classRef as Ptr) as CFStringRef

dim nsscript As ptr=initWithSource(alloc(NSClassFromString(“NSAppleScript”)),TheScript)
dim err As ptr
dim descriptor As ptr=executeAndReturnError(nsscript,err)
if err<> nil then
MsgBox “An error occured”
//MsgBox stringValue(descriptor)
end if[/code]