tags:

views:

64

answers:

2

I'm really not sure where to start looking on this one.

I want my cocoa app to read the text from another application running on my mac. It is a simple text window, with copy-paste functionality. I would love to be able to find the window programmatically and drill down to some 'text' attribute, or maybe intercept each text drawing call, but would settle for automating switching to the window, selecting all, and pasting somewhere (every 100 milliseconds for example).

Any ideas?

UPDATE - I don't think either of the selections below will work - the accessibility inspector doesn't display the contents of the window I want to scrape, and it isn't applescript-able. Any other ideas? Even just away to automate switching focus, copying, and pasting.

A: 

Use the Accessibility API. The user will need to have access for assistive devices turned on.

Peter Hosey
Thanks for the suggestion, but I think some measures have been taken to prevent this. I'll make sure first though.
Ben Packard
If you've tried it and it's not working, make sure *you* have access for assistive devices turned on. ☺
Peter Hosey
haha yeah I checked, thanks anyway!
Ben Packard
Just to clarify, the window I'm trying to crape seems to have prevented it - all other windows are read ok
Ben Packard
A: 

As an alternative to Peter's suggestion, you might try AppleScript. You can direct it (and use its results) from Cocoa. Just another means to an end, especially if you're trying to do something basic like "get the text of the frontmost window of the active application". It's probably easier but relies on the app supporting AppleScript. It may, however, be enough for your purpose.

Joshua Nozzi
Yep, the app definitely doesn't support applescript. Thanks though.
Ben Packard