我希望在运行时创建aAppleScript:
字符串总是一样的
搜索
这将在textmate - 我想在textmate做这件事中使用
我知道我可以使用textmate的查找和替换功能--我只是尝试一下自动化。
这只应在当前页上进行更改。
这个是可能的吗?
UPDATE:所以我找到了一些代码让我开始.
tell application "TextMate" to activate
tell application "System Events"
keystroke "f" using {command down}
tell process "TextMate"
keystroke "<?"
keystroke tab
keystroke "<?php"
click button "Replace All"
end tell
keystroke "esc"
end tell
但我得到了以下错误:
error "System Events got an error: Can’t get button \"Replace All\" of process \"TextMate\"." number -1728 from button "Replace All" of process "TextMate"
在Textmate的“查找和替换”对话框中,按钮被标记为“替换所有”,我在这里遗漏了什么吗?
发布于 2010-01-12 13:08:03
你得把击键发送到合适的窗口。比如tell window "find dialog"
(或者其他什么)。你必须是完全明确的,所以可能是
tell tab 1 of pane 1 of window "find and replace" of app textmate...
用户界面脚本太麻烦了,你只能作为最后的手段来做。
看来你需要sed。
在命令行上,或使用do shell script
cat /path/to/your/file.php|sed "s_<?_<?php_g">/path/to/your/newfile.php
或者整个文件夹的价值
cd /path/to/your/folder
for file in *.php; do cat "$file"|sed "s_<?_<?php_g">"${file/.php/-new.php}"; done
发布于 2010-01-11 19:23:19
最好还是看一下MacScripter;有很多示例和解决方案可以使用Applescripts分隔符:MacScripter /搜索结果来查找和替换是否使用文本分隔符,如下所示:
on replaceText(find, replace, someText)
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to find
set someText to text items of someText
set text item delimiters of AppleScript to replace
set someText to "" & someText
set text item delimiters of AppleScript to prevTIDs
return someText
end replaceText
发布于 2011-11-15 22:16:44
在AppleScript字符串中进行搜索/替换,或者将它们发送到Mac的底层Unix工具(如sed和Perl ),这一切都是非常好的,但它们通常并不能真正替代直接搜索/替换目标应用程序中的文本。
我也遇到了同样的问题,尽管我用的是龙条,而不是TextMade。谷歌带领我来到这里,我对没有找到直接的解决方案感到沮丧。所以让我分享一下我想出的那个:
set find to "the"
set replace to "THE"
tell application "Dragon Dictate"
activate
tell application "System Events"
tell process "Dragon Dictate"
keystroke "f" using {command down}
keystroke find
keystroke tab
keystroke replace
tell window "Find"
click button "Replace All"
end tell
end tell
end tell
end tell
关键的区别是寻址窗口,它知道“替换所有”按钮。当然,你还必须将“龙字典”目标应用程序更改为"TextMate“。(AppleScript似乎需要确切地知道脚本所针对的应用程序,除非您想要返回到某个真正丑陋的低级消息发送中。当与AppleScript打交道时,这只是一天中的第337次叹息!)
https://stackoverflow.com/questions/2044094
复制相似问题