I am working on a script that finds all my image files and transfers them to a single folder… but I can’t format my find command to be used in applescript…
tell application "Finder"
set theList to do shell script "find ~/Documents -name *.tiff -exec cp {} ~/AllImages ;"
return theList
end tell
You need to double-escape the relevant characters.
As written, AppleScript interprets the backslash as an instruction to escape the next character and pass it through as-is, but then ‘do shell script’ doesn’t see the backslash.
Double-escaping takes case of it - AppleScript sees the first escape and this allows it to pass the second backslash to the shell.
set theList to do shell script "find ~/Documents -name *.tiff -exec cp {} ~/AllImages \;"
I have to raise this topic again, since I seem to cannot get my escapes right. I want to take advantage of find’s features and need to get a backslash in front of the brackets and the ! sign.
The command to pass to the shell would look something like this:
Mark, the backslahes in front of the brackets and the exclamation sign.
This one obviously does not work and I even did not expected it to work:
set findCommandString to findCommandString & "( -iname " & quoted form of searchFileName & " -and ! -iname " & quoted form of excludeFiles & ") "
But this one doesn’t work either and this is where I am stuck:
set findCommandString to findCommandString & "\\( -iname " & quoted form of searchFileName & " -and \\! -iname " & quoted form of excludeFiles & "\\) "
In the log I see this command sequence:
“The find cmd: /usr/bin/find /Users/sbduach/Documents \( -iname ‘julia’ -and \! -iname ‘._*’\) -type f -print 2> /dev/null”.
As you see, all the backslashes have doubled. Of course I can’t just use one backslash, so what am I supposed to here?