0

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 a way to automate switching focus, copying, and pasting.

2 Answers 2

0

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

3
  • Thanks for the suggestion, but I think some measures have been taken to prevent this. I'll make sure first though. Dec 29, 2009 at 17:15
  • If you've tried it and it's not working, make sure you have access for assistive devices turned on. ☺ Dec 30, 2009 at 3:27
  • Just to clarify, the window I'm trying to crape seems to have prevented it - all other windows are read ok Jan 5, 2010 at 6:16
0

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.

1
  • Yep, the app definitely doesn't support applescript. Thanks though. Dec 29, 2009 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.