我发现下面的AppleScript找到并替换了......但是在这种情况下我不想用“401”替换,而是希望用剪贴板上的内容替换它。
所以我试图把类似的东西:set stringToReplace to keystroke "v" using command down
...但是这不起作用(预期行尾等,但找到了标识符。)
以下是代码:
on run {input, parameters}
set stringToFind to "404"
set stringToReplace to "401"
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
return input
end run
答案 0 :(得分:1)
解决了这个问题:
我需要做的就是在the clipboard
set stringToReplace to
on run {input, parameters}
set stringToFind to "404"
set stringToReplace to the clipboard
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
return input
end run