我正在尝试使用 AppleScript 自动手动查找和替换,但没有运气。
有没有办法做到这一点?
没有直接的方法可以做到这一点。Xcode 4 中的脚本没有我们许多人希望的那么健壮。您可以使用 GUI 脚本来完成。这是一个示例脚本,用于设置查找和替换文本,然后单击“全部替换”按钮。显然,您会想要修改它以供自己使用,但它说明了原则。
tell application "Xcode"
activate
end tell
tell application "System Events"
tell process "Xcode"
keystroke "f" using {command down, option down}
set value of text field 1 of group 1 of splitter group 1 of group 2 of splitter group 1 of group 1 of front window to "<string>"
set value of text field 2 of group 1 of splitter group 1 of group 2 of splitter group 1 of group 1 of front window to "<string2>"
click button "Replace All" of group 1 of splitter group 1 of group 2 of splitter group 1 of group 1 of front window
end tell
end tell