0

So i want to try and make a script that will find and delete multiple folders in a folder with applescript:

tell application "Terminal"
    activate
    do script "find (Path to folder) -type d *-name "Foldername*" -exec rm -rf {} \;*"

end tell

Applescript wont run anything after -type d because of "Syntaxerror expected end of row" but I dont understand why because it works if i run

find (Path to folder) -type d *-name "Foldername*" -exec rm -rf {} \;* 

in terminal

1
  • Is there a reason why you don't use the do shell script command?
    – user309603
    Sep 23, 2014 at 6:49

1 Answer 1

2

You could use the command do shell script which does the same thing as running it in Terminal. And you don't need a tell block to run this.

Also here are a two points to look at in your script.

  1. If you want to use " quotes in your already quoted shell script then you need to escape them using \. i.e. "some script \"some name\" some more script". Otherwise, just use single quotes in your double quoted script.

  2. If you want a \ to be run in your script then you need to escape it in Applescript. i.e. rm -rf {} \\;*"

Final script would look something more like this:

do shell script "find (Path to folder) -type d *-name 'Foldername*' -exec rm -rf {} \\;*"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.