Applescript在多个文件中查找和替换文本

时间:2013-12-26 18:56:16

标签: text replace find applescript textedit

我在文件夹中使用TextEdit创建了多个文本文件。我想使用AppleScript在所有这些字符串中查找并替换相同的字符串。

我是AppleScript语言的新手。我用它制作了非常简单的脚本。 你能告诉我代码吗?

感谢。

1 个答案:

答案 0 :(得分:1)

这解决了我的问题。

set myFiles to (choose file with multiple selections allowed)

display dialog "Text to replace" default answer ""
   set textToReplace to text returned of result

display dialog "Text to insert" default answer ""
   set textToInsert to text returned of result

repeat with aFile in myFiles
   set myData to do shell script "cat " & quoted form of (aFile's POSIX path)
   set newData to do shell script "echo " & quoted form of myData & " | sed 's/" & textToReplace & "/" & textToInsert & "/g' > " & quoted form of (aFile's POSIX path)
end repeat