Text 自动替换器替换文本文件中的文本

Text 自动替换器替换文本文件中的文本,text,automator,Text,Automator,我完全不知道如何编码,有几个星期我一直在玩automator,Mac OS。。。但是当我尝试创建一个自动请求文本,然后根据答案,我可以替换文本文件中的几个“变量”,然后只保存这个文本文件时,我就卡住了 我曾尝试使用此代码,但apple脚本中始终存在一个错误: set stringToFind to "replace that" set stringToReplace to "with this" set theFile to choose file set

我完全不知道如何编码,有几个星期我一直在玩automator,Mac OS。。。但是当我尝试创建一个自动请求文本,然后根据答案,我可以替换文本文件中的几个“变量”,然后只保存这个文本文件时,我就卡住了

我曾尝试使用此代码,但apple脚本中始终存在一个错误:

set stringToFind to "replace that"
set stringToReplace to "with this"
set theFile to choose file
set theContent to read theFile as «class utf8»
set {oldTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, stringToFind}
set ti to every text item of theContent
set AppleScript's text item delimiters to stringToReplace
set newContent to ti as string
set AppleScript's text item delimiters to oldTID
try
    set fd to open for access theFile with write permission
    set eof of fd to 0
    write newContent to fd as «class utf8»
    close access fd
on error
    close access theFile
end try
你知道如何掌握它吗?或者在哪里寻找答案?我花了几个小时试图解决它,但没有任何进展。。。先谢谢你


您遇到了什么错误?请注意,代码需要位于
runapplescript
操作的
Run
处理程序中才能获得输入。