How to get the method name where the caret currently is from Xcode?

83 views Asked by At

After one month of googling I can't find a solution to my problem and I'm getting desperate. I found many unrelated topics around (and I expected more discussions on Xcode in general), some discussions are stating that Apple does not want to give official API for Xcode (strange) and there are no official ways to develop applications and plugins working with Xcode.

So I am developing an application for keeping track of simple user activity in Xcode (currently I have Xcode 4.6 and OS X 10.8.5 Mountain Lion). Where I got hardly stuck is where I have to get the name of the method where currently the caret is situated. I'm trying to achieve this with AppleScript since other parts of my application are in AppleScript as well and would be great to stick to that.

I tried by getting the properties of the text document but Xcode does not return many useful things. I tried also to enable access for assistive devices and applications (manually and with a script) but without result.

I'm convinced there will be a way to get that method name since it appears in the upper part of the window, so Xcode has this information and I just don't know how to reach it.

Any help will be highly appreciated!! Many thanks!!!

1

There are 1 answers

1
Johnathon Sullinger On

Xcode gets that information by parsing the code file and building the members list. If you want to determine what method you are in, you will need to parse the entire file yourself. If the AppleScript can give you the line number the caret is at, then you can parse and determine what method it is in manually.