I have a simple AppleScript that calls a perl shell script to replace a string with another string (here one with two) in files with specified file extensions (here .txt and .xyz).
It used to work exactly as I have it below, but no longer does (possibly since updating to Mojave last year).
set CleanFiles to "
s/one/two/g;
"
set myFolder to choose folder with prompt "Choose a folder with files to be cleaned up:"
set theFolder to POSIX path of myFolder
do shell script "find " & theFolder & " \\( -name \\*.txt -o -name \\*.xyz \\) -print0 | xargs -0 perl -i -pe '" & CleanFiles & "'"
There is no error message, it seems to run but doesn't do anything.
What could be wrong?
CleanFiles
in the first line, but useCleanElanFiles
in the last line. is that the problem, or just a transcription error?set theFolder to quoted form of (POSIX path of myFolder)
. When I do that on my test folder your script seems to work.quoted form of
whenever you think there's a chance that whitespace might sneak into a variable. Just remember that unix uses space as a delimiter, and that if an unquoted space gets tossed in you'll turn what should be one argument into two, and throw off the entire argument list. I'll add an answer...