Can someone help me understand the difference between events and
commands. It seems that at the language level that are the same thing,
similar to objective-c methods. From what I've read it seems like
events are handlers that scripters will define so that they can get
callbacks by some other application, while commands are handlers that
scripters call to effect some other scriptable object.
This is about right. The difference between a command and event is who
sends it. I think of commands as something that a script can order an
application to do, and events as something that an application can have
a script do, if the script supports it.
But I'm unsure how this difference is supposed to be documented. For
example it seems to me that Mail.app's
on perform mail action with messages theMessages for rule theRule
would be categorized as an event. But in the scripting dictionary it's
documented as a command, and I'm not sure how I am supposed to learn
that if I provide a handler for this command in my own script I will
get a callback from Mail.app.
The Script Editor's dictionary window does not distinguish between
events and commands. The documentation has to make it clear to the
user. In my own app's dictionary, events' comments read "Sent by
Mackersea [my app] when yadda yadda yadda."
Other applications (I'm looking at Retrospect now) seem to handle
things a little differently, they say to save your script as an
application and make sure to check "Stay Open" and "Never Show Startup
Screen". I'm not sure if these are necessary steps or just
recommendations.
The problem here is to give the app enough information to address the
command (i.e. the event) appropriately. There are some posts on the
subject way back in the applescript-implementors archive. From what
I've gathered, the most universal solution is for the user to write the
event handler in a script object, and for him to pass the script object
to the app, which saves the object somewhere. Later, when the app needs
to post the event, it sends the command to the script object.
For example, my app has an "offer" command to upload files. An optional
parameter to the offer command is "notifying", which takes a script
object. The command returns a "transfer" object. Then, when the upload
is complete, my app will call an event, "finished transfer", on the
script object. The "finished transfer" event received by the script
object has one parameter, the "transfer" object returned by the "offer"
command.
Retrospect takes a different approach, which (I think) involves saving
the return id attribute of the commands it receives, and using that to
address commands (i.e. events) back to the originator. But as you've
noticed, that only works if the script is saved as an application
object.
My goal is to allow users of my application to define similar
applescript handlers so that they can respond to events in my app. I'm
looking for recommended reading on best practices for doing this.
Matt Neuburg's "AppleScript: The Definitive Guide" provides a lot of
info on the use and capabilities of script objects, and is worth buying
regardless.
Here are some relevant links, mostly from the applescript-implementors
archive (which, BTW, looks to have been improved recently):
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-implementors mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden