I'm having some issues with "do shell script" syntax

I’ve got a very sloppy app right now with the code below for cleaning my PSP of mac files, but as it is, I’m GUI scripting it because I don’t understand how to use “do shell script” properly… When I was playing trial and error before I moved onto GUI scripting, I accidentally wiped all 3 volumes on my computer (Start up disk, PSP, EHDD) clean of all mac files listed in the code below so I’m not too keen on giving it any more goes. :confused: It did so because I think it was treating each line as it’s own shell so the ‘rm’ stuff ended up running by itself without the directory change. Having said that, how do I go about getting both lines running in the same shell? And on top of that be able to eject the drive when it’s done.

activate application "Terminal"
delay 0.5
repeat until exists window 1 of application "Terminal"
	delay 0.5
end repeat
activate application "Terminal"
tell application "System Events"
	keystroke "cd /Volumes/CHRIS\\ PSP/"
	keystroke return
	keystroke "find \".\" \\( -name \".DS_Store\" -or -name \".Trashes\" -or -name \"._*\" \\) -exec rm -rf \"{}\" \\; -prune"
	keystroke return
end tell

As it is, I can’t quit Terminal, and I can’t eject the drive when it’s done because I’m just using keystrokes so I have no way besides using “delay” to time it correctly… Help please! >.<

Assuming you can help me out, here’s the code without all the excess back slashes and the eject code.

cd /Volumes/CHRIS\ PSP/
find "." \( -name ".DS_Store" -or -name ".Trashes" -or -name "._*" \) -exec rm -rf "{}" \; -prune
tell application "Finder"
	eject disk "CHRIS PSP"
end tell

Hi Chris, try this:

set diskName to "/Volumes/CHRIS\\ PSP"
do shell script "find " & diskName & " \\( -name '.DS_Store' -or -name '.Trashes' -or -name '._*' \\) -exec rm -rf '{}' \\; -prune"
do shell script "diskutil unmount " & diskName

what ist that “; -prune” for?

I can honestly say, I haven’t the slightest idea. :stuck_out_tongue: I pulled that line of code off like macrumors.com or something from some user talking about using it with Drop Script and I’m just applying it to Applescript. I haven’t even scratched the surface of UNIX yet so I know next to nothing.

:lol:, I would never use a line with rm -r in it with any unknown additional parameter

Edit: I see, it’s a part of the find command

Heh, yeah it just so happens I grabbed ‘Unix in a nutshell’ from the library awhile back and only recently did I understand the joke on the back, “Suddenly Murray learned that Pablo was only joking when he said that “rm -rf /” was the UNIX command for a directory listing.” :wink: I nearly ran it out of curiosity, and boy am I glad I didn’t. That would have sucked! :mad: Although at the same time, I’m not sure it would have worked because I think it would’ve needed to be ~/ specifically to wipe my drive. “rm -rf *” would probably do it too.

If your curious, I think I got the syntax right for the PC equivalent. :wink:

del c:*.* /f /q


-prune in the find command (searching not recursivly) works only, if it’s placed right after the volume name

do shell script "find " & diskName & " -prune \\( -name.

At the end of the line it has no effect