문제

I've multiple text files made with TextEdit in a folder. I want to find and replace a same string in all of them using AppleScript.

I'm a total newbie to AppleScript language. I've just made very simple script with it. Would you please suggest me the code?

Thanks.

도움이 되었습니까?

해결책

This solved my problems.

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top