Re: Scripting Xcode to open a source code file and go to a particular line number
Re: Scripting Xcode to open a source code file and go to a particular line number
- Subject: Re: Scripting Xcode to open a source code file and go to a particular line number
- From: Christopher Nebel <email@hidden>
- Date: Mon, 27 Apr 2009 15:44:02 -0700
On Apr 26, 2009, at 10:05 PM, Brooks Bell wrote:
I'm writing a Cocoa utility that scans crash logs. I have the
source code
file name and line number of the crash and I'd like to open the file
in
Xcode and scroll to the line in question.
At this point I'm doing it with SystemEvents:
tell application "Xcode"
activate
open "%@"
tell application "System Events"
keystroke "l" using {command down}
keystroke "%@"
keystroke return
end tell
end tell
(the %@ symbols get replaced before running with the file path and
line
number).
Is there a better way to initiate Xcode's "go to line #" function?
First, Xcode has a real scripting interface for this sort of thing,
namely the "selection" property of text documents:
tell application "Xcode"
tell front text document
set its selection to paragraph 100 of it -- goes to line 100.
end tell
end tell
Second, don't compile and run AppleScript scripts to implement
features in an Objective-C app -- it's incredibly wasteful, and is
often more complicated than the alternatives. Use Apple events
directly, or Scripting Bridge, or appscript. Alternatively (though
less efficiently), invoke xed(1).
--Chris Nebel
AppleScript Engineering
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden