如何使用AppleScript写入Xcode文件?

时间:2014-01-22 04:22:25

标签: xcode applescript edit

假设我打开了一个Xcode项目。 (例如,假设main.m已打​​开进行编辑。)我想使用AppleScript写入代码。

以下AppleScript适用于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

但是,我无法使用Xcode。 (我改变AppleScript说 告诉应用程序“Xcode” 代替 告诉应用程序“TextWrangler”。)

AppleScript字典中的“选择”一词用于Xcode,但AppleScript拒绝以下每个命令:

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

是否有人建议如何使用AppleScript写入Xcode源代码文件?

我正在使用Xcode 5.0.2和TextWrangler 4.5.1。我在Mac OS X 10.8.5版和10.9.1版上运行的结果相同。

谢谢。

1 个答案:

答案 0 :(得分:1)

如果我打开了一个Xcode项目并选择了一个源文件,我可以使用以下命令获取属性:

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

示例结果:

  

{contents:“sourceContent [snipped]”,选定的段落范围:{14,14},名称:“AppDelegate.h”,选择:应用程序“Xcode”的源文档“AppDelegate.h”的插入点272

(希望它有助于摆弄并将TextWrangler语法翻译成Xcode)

相关问题