Embedding AppleScripts?

According to Chat GPT, you can embed AppleScripts into your Xojo app. It looks something like this:

Var appleScript As String = _
"tell application \"Pages\" to activate" + Chr(10) + _
"tell front document" + Chr(10) + _
"  -- Define the list of notes and their semitone values" + Chr(10) + _
"  set noteList to {\"C\", \"C#\", \"D\", \"D#\", \"E\", \"F\", \"F#\", \"G\", \"G#\", \"A\", \"A#\", \"B\"}" + Chr(10) + _
"  set semitoneShift to " + transposeFromIndex.ToString + " as integer" + Chr(10) + _
"  tell current page" + Chr(10) + _
"    set textBoxList to every shape" + Chr(10) + _
"    repeat with thisBox in textBoxList" + Chr(10) + _
"      tell thisBox" + Chr(10) + _

Has anyone ever tried this? When I deploy my app, I want it to run on any MacOS machine without having to reference an actual AppleScript. Or does dragging an AppleScript into your project accomplish that?

Thanks!

Bingo. Drag the script in and then you can call it by name in your code.

Thanks for that!

I wasn’t sure, because when I double click on the AppleScript (the one I dragged into my project), it opens up in Script Editor. And the file path leads right back to the original AppleScript. So, I didn’t know if that indicated a continued dependency upon the external AppleScript.

Thanks again!

.

Oh yes, the script will need to continue to exist. Dragging the script file into the IDE adds it to your project in a way that the IDE will collect the script from that location when you build.

If you delete the source script from the disk and then open the project, you will see this:

So then, the script will have to exist on whatever machine runs the app. Do you know of a way that can be circumvented?

Script build. Check the docs.

Yes, but it is embedded inside the application bundle by the build process, so the whole package is self contained. Does that resolve your concern?

You could embed it as a constant or string much like your original post.

Embeding it as a string like in my original post was highly problematic, which is why I asked if anyone had any experience with that approach. But as long as there’s no need for an extra step of housing that script on every machine the app runs on, yes. That resolves my concern.

Thanks so much!