formating shell script find command?

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

I get an error on the escaped ; (:wink:

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 \;"

doh! i totally forgot about escaping the escape character. thanks a bunch… it works like a charm!

Hi guys,

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:

/usr/bin/find /Volumes/JvMpreprint/DTP ( -iname ‘bmw’ -and ! -iname ‘._*’ ) -type f -print

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?

Thanks,
budy

Ahem, yes.

Those things are sometimes hard to debug, but I should have seen the missing blank.
I was so drawn away by the quoting that I have missed it.

At least I knew how to make it work in general, being an AS newbie. :wink:

Thanks a lot,
budy