Re: Send events to AppleScript
Re: Send events to AppleScript
- Subject: Re: Send events to AppleScript
- From: has <email@hidden>
- Date: Sat, 21 Mar 2009 02:38:33 +0000
On Mar 21, 2009, at 1:06 AM, Тимофей Даньшин wrote:
On Mar 21, 2009, at 3:34 AM, has wrote:
Is it at all possible to have an application send actions to a
particular AppleScript script,
Yes. See NSAppleScript/OSAKit/Carbon OSA APIs. There's a sample
project in the objc-appscript repository, CallAppleScriptHandler,
that provides a simple demonstration of calling script handlers
from ObjC, using appscript's AEM APIs to simplify the process of
converting Cocoa objects to/from NSAppleEventDescriptors.
Sorry for misleading you, i rather meant "receive events" from third
party applications.
If you want to run an AppleScript as a standalone application and send
it events from other applications, save your script in Script Editor
as a 'stay open' application. As for sending events from Cocoa(?) apps
to this applet; there's a couple ways you could arrange that, but
you'd need to provide more details on what the setup needs to do if
you want specific advice.
Or do you mean that you want to write a Cocoa application that
forwards some/all incoming events to an embedded AppleScript? In that
case you want either NSAppleEventManager, or possibly Cocoa Scripting,
to handle incoming events, and NSAppleScript or OSAKit to host the
script, and write some glue code to go inbetween.
or set that script as a delegate of that application
Depends exactly what you mean by 'delegation'. The OSA API provides
a whole bunch of arcane selectors and callbacks for two-way intra-
process integration between application and scripts, but whether
it's appropriate/how to use it will depend on exactly what you're
trying to achieve.
By delegation I mean the form of delegation that is present in
Objective-C, when one can register one's object with another object
as it's delegate and receive messages from in on certain occasions,
such as textViewDidChangeSelection:
That's pretty much what the OSA API was designed to do [1] - allow a C/
C++/ObjC application to load a script and invoke its handlers (what
AppleScripters call 'attachability'). See Folder actions, Mail rule
scripts, etc. Satimage Smile, for example, provides a great
demonstration of just how far you can go with this sort of thing.
HTH
has
[1] With the caveat that the OSA API is somewhat over-complicated,
under-documented, lame in parts, and only really practical for
AppleScript despite being theoretically language agnostic.
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden