Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

The following code to purge a directory recursively does not work because I cannot get past the Application Support folder.

try
    do shell script "rm -r ~/Library/Application\ Support/Google/Chrome/Default/Pepper Data/Shockwave Flash"
end try
  • If I use ~/Library/Application Support/Google... nothing happens. Which is expected.
  • If I use ~/Library/Application\ Support/Google... I cannot save the script due to the error message: Syntax Error Expected “"” but found unknown token.

How can I work around this error?

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

Try:

set pathwithSpaces to "/Users/John/Desktop/This is a test.docx"
do shell script "rm -r " & quoted form of pathwithSpaces
share|improve this answer
    
Iz works1111 Thank You :) –  gentmatt Feb 21 '13 at 18:31
add comment

You have to double the backslashes and also escape the other spaces:

do shell script "rm -r ~/Library/Application\\ Support/Google/Chrome/Default/Pepper\\ Data/Shockwave\\ Flash"

Or escape the path some other way:

do shell script "rm -r ~/'Library/Application Support/Google/Chrome/Default/Pepper Data/Shockwave Flash'"

quoted form of replaces ' with '\'' and surrounds the string with single quotes, so it doesn't work with paths that start with ~/.

share|improve this answer
    
This is even better! Thanks –  gentmatt Feb 22 '13 at 7:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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