Re: Send an event to another app
Re: Send an event to another app
- Subject: Re: Send an event to another app
- From: Christopher Nebel <email@hidden>
- Date: Thu, 6 Mar 2008 09:26:45 -0800
On Mar 5, 2008, at 8:40 PM, Nick Zitzmann wrote:
On Mar 5, 2008, at 9:20 PM, Alex Kac wrote:
I realize that under OS X things are different and they simply
don't work that way. I also know that menus do have a handler and I
*assume* that even if a menu is greyed out or a sheet is open
(which I understand is modal) that the main window can still handle
events or messages. So what I want to do under OS X is write my own
app that periodically will force this app to save its document by
calling the same handler as what the Save menu command would call.
Again, I do realize that "bad things may happen", but for this app
we are using its worth trying for me.
Typically you'd do this by issuing an AppleScript command, which you
can do with the NSAppleScript class. Something like "tell
application MyApp to save document in front of documents" ought to
work if the hypothetical MyApp is an NSDocument-based application.
The correct script (while the above does happen to be syntactically
valid), the proper script would be 'tell application "MyApp" to save
front document". ("save document 1" would be equivalent.)
However, that doesn't guarantee that the application will do anything
with the command. Presuming that this is a Cocoa application you're
dealing with, it would have to (a) be NSDocument-based, and (b) have
declared itself to be scriptable, which application writers are not
required to do. Try dropping the application on Script Editor and see
if you get anything.
It's also possible to drive an application by manipulating its UI
using the Accessibility API, but that wouldn't work in your case,
since it would amount to clicking the "Save" menu command, which you
say is disabled. I'm not sure what the goal here is. If it's to find
out whether or not the application freaks out when asked to save
something that it's already trying to save, then if it's impossible to
ask it to do that, then your question would appear to be answered.
--Chris Nebel
AppleScript Engineering
_______________________________________________
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