Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
RE: Subroutines
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Subroutines



Oops -- just read Jon's response to your post -- if you don't want to handle
it, do what Jon says. If you do want to handle it, then you've got to jump
through these hoops:


The kASSubroutineEvent event is usually used in the case that you want to
call an AppleScript handler from your compiled C / C++ / pascal code. For
example, you want to let the user write an action function for something,
lets say you have a dialog with a button and some edit text. When the
button is clicked, you want to send the contents of the edit text to a
handler which the user has defined somewhere else.

User writes a script:

script Fred
to doButtonPush(someText)
say someText
end doButtonPush
end script

and installs the script somehow, either like this

tell app "myApp"
set the button action script to Fred
end tell

or by having an application script loaded at app launch time.

Now when user presses the button, you'll run the doButtonPush handler in
Fred by sending a kASSubroutineEvent to the script context ( i.e. the OSAID
) you created when you got the
'set the button action script to' message ( or when you launched the app and
loaded the application script ).

You create the kASSubroutineEvent apple event like normal, but you call
OSADoEvent instead of AESend, and you use the string 'dobuttonpush' instead
of 'doButtonPush'.

In your case, it seems you want to have an external script call a
doSomething routine. In this case, if you get the kASSubroutineEvent, you
can handle it by just calling OSADoEvent, but remember you'll need to create
an OSAID at some point, and the script you compile to make the OSAID needs
to have a doSomething handler in it, and the prototype needs to match
exactly for everything to work ( there's no prototype checking ) .

Hope that helps you get started. Anyone with more precise information,
please correct what I've said, because it's been awhile since I did this.

- Olof




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.