AppleScript runs from module not from plain code

Mac 10.14.6
Xojo 2021 3.1
Puzzling (to me) behavior of calling AppleScript from Xojo.
I have an AppleScript that I have written that simply speaks: Hello World. I use it for testing purposes.

The name of the AppleScript is Show. I have dragged the AppleScript to the Navigator bar.

I have a button (pbTest) and in the Pressed event I have one line of code: Show. It autocompletes. But when I run the program and click on this button, nothing happens.

Now I create a module which I call TestCode. It has a single method: DoTest. DoTest contains a single line of code: Show.

Now if I put in the pressed event of *pbTest a single line of code: TestCode.DoTest it works. I hear the computer speak Hello World.

Why can I not call the AppleScript directly in the code of the button press? Why does it work just fine if I write the single line of code in a method of a module and then call this module method in the code of the button press?

Code of the button press event:

// TestCode.DoTest


// Show

TestCode.DoTest is a single line of code:

// just one line of code

I think this would call the Show method of the button’s window, not the AppleScript.


Hi Robert,

why don’t you use Speak ?

Show is a reserved word in the context of a Window or control
A module is not one of those.
Try renaming the Applescript to Banana (for a silly example) and see what happens.

1 Like

in the run handler just do:

dim s as string
s = [name of applescript]

so if I drag an AppleScript in to Xojo called “Quit PB Progress Bar. scpt”
it appears as Quit_PB_Progress_Bar in the navigator

so dim s as string
s = Quit_PB_Progress_Bar

launches the script.

Jeff (& Carsten), that seems to have been the problem. Banana works. I lost a couple hours of my life to this issue. It would be nice if the IDE displayed Show in a different color to hint at its status. Your help is appreciated. Obviously, the different meaning of Show in the two contexts did not occur to me.

Emile: I was using the code in the AppleScript just for testing purposes. Having it talk was just an easy way to detect if it was successfully launching.