How do you make an ApScript Studio App receive events?

How do I program my AppleScript application (developed using AppleScript Studio) to receive events?

In particular I want my application to respond to an event triggered by a shell program using an osascript command.

My problem is related to do shell script - I want my AppleScript application to run shell command in the background and I want it to receive an event when the shell script has finished.

Many Thanks

Your AppleScript Studio app is already very scriptable. Try creating a button called “receiver” that is placed behind a text view or just out of the bounds of the main window. Then attach an “on clicked” handler to the button that does something useful. Now, from anywhere (including the shell) you can have your app receive an event and do something useful with this code:

tell application "yourapp" to tell button "receiver" of window "main" to perform action

You’re right that you can use “osascript” to trigger this from a shell script:

osascript -e 'tell application "yourapp" to tell button "receiver" of window "main" to perform action'

Jon

Thanks Jon - I will try this but is there not a more elegant way than using hidden buttons?

Oh, sure, you can add a full custom scripting dictionary to your app but the overhead is huge and so not worth it (see the MacScript FAQ for more info). If you just want to fill in text fields and the like, the same code you use inside your app is available outside of it (e.g., set contents of text field “x” to “123”) but for running custom handlers, this is far and away the easiest (and in my opinion) most elegant way of handling scriptability.

Jon

Thanks Jon.

I trust your experience and will use the “hidden button” approach.

For reference how would I go about writing a customised dictionary? This is what I expected to have to do but couldn’t find any help in the documentation :frowning:

I take it all back the “hidden button” approach is very elegant.

I am actually able to include hidden buttons in a window (it is a tickable property in Interface Builder). Therefore there is no need (as far as I can see) to hide them behind another object of off the edge of the window as suggested above.

It was the suggested physical placement of the buttons in hard to see places which I considered to be “unelegant” :lol: