【问题标题】:Applescript find and replace text in multiples filesApplescript 在多个文件中查找和替换文本
【发布时间】:2014-01-14 09:34:11
【问题描述】:

我在一个文件夹中有多个使用 TextEdit 制作的文本文件。我想使用 AppleScript 查找并替换所有字符串中的相同字符串。

我是 AppleScript 语言的新手。我刚刚用它制作了非常简单的脚本。 请给我推荐一下代码好吗?

谢谢。

【问题讨论】:

  • 我刚刚用谷歌搜索并尝试了一些我发现的东西。它们都不适合我,但可能是因为我不是 AS 代码专家,所以我真的需要从头开始。
  • Stack Overflow 不是请求免费工作的地方。一旦您发布代码以证明您已经为问题付出了一些努力,许多用户将很乐意提供帮助。不要担心它是否有效或是否“好”。
  • 谢谢,对不起。我会尝试做一些更深入的尝试。再次感谢。
  • @Neuran 将您的解决方案添加为答案并接受它。然后从 yoru question 中删除更新。这将通知用户问题已解决,他们不需要点击进入。谢谢
  • 感谢@markhunte 真的很有帮助;)

标签: text replace find applescript textedit


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-26
    • 2013-01-29
    • 2013-12-26
    • 2011-07-29
    • 2012-08-29
    • 2014-08-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多