On Mar 21, 2009, at 5:38 AM, has wrote:


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.

Well, I'm writing a "translation memory" application, which is a program that grabs sentence by sentence from a given text (that needs translating), asks the user to translate that sentence and stores the translation and the original in a database. If the user comes across the same sentence again in the future, he or she will not need to translate it again. I thought i would take the TextEdit app as the text editing part of my project, but as I wrote the database management and the search parts, it turned out that TextEdit is not capable of correctly interpreting word files or RTF's (ie it ignores footnotes, headers/footers and a lot of other stuff). That is why I am trying to find out how i can communicate with Word or Pages. As far as what I would want from an AppleScript (if I were to use AppleScript) is to be able to receive notifications from Word when, for example, the user has hit a certain key combination, to know where the insertion point (or selection) is in Word and to receive notifications when it moves, to be notified when a user is trying to edit something and prevent him/her from doing so if that part of the text should not be edited. Receiving those notifications, that script would just redirect them to my application and receive responses to them and redirect them to Word. In case of scripting bridge, the logic I described for AppleScript would be in my application. But having read what I found and had time to read, I'm not quite sure yet I can be notified of the things going on in another application (such as Word, for example).



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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to