Pat
Pat

Reputation: 13

How use AppleScript, to write to an Xcode file?

Suppose I have an Xcode project open. (For example, suppose main.m is open for editing.) I'd like to write to the code using AppleScript.

The following AppleScript works fine with TextWranger:

set string_to_write to "asdf"
set string_size to count string_to_write

tell application "TextWrangler"
    activate
    set selection to string_to_write
    select insertion point after character string_size of selection
end tell

However, I can't get it to work with Xcode. (I changed the AppleScript to say tell application "Xcode" instead of tell application "TextWrangler".)

The word "selection" in the AppleScript dictionary for Xcode, but AppleScript rejects each of the following commands:

selection
selection of document 1
character 1 of document 1
character 1 of source document

Does anyone have a suggestion on how to write to an Xcode source code file, using AppleScript?

I'm using Xcode 5.0.2 and TextWrangler 4.5.1. I got the same results running on Mac OS X version 10.8.5, and on 10.9.1.

Thank you.

Upvotes: 1

Views: 578

Answers (1)

user1804762
user1804762

Reputation:

If I have a Xcode Project open and a source file selected I can get the properties with this:

tell application "Xcode"
    get properties of source document 1
end tell

Example Result:

{contents:"sourceContent [snipped]", selected paragraph range:{14, 14}, name:"AppDelegate.h", selection:insertion point 272 of source document "AppDelegate.h" of application "Xcode"}

(hope it helps to fiddle around and translate that TextWrangler Syntax into Xcode's)

Upvotes: 1

Related Questions