16

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?

3 Answers 3

12

Try:

set pathwithSpaces to "/Users/John/Desktop/This is a test.docx"
do shell script "rm -r " & quoted form of pathwithSpaces
0
13

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 ~/.

0
6
do shell script "open -n /Applications/App\\ Store.app"

Handle the space with \\.

For example replace App Store.app with App\\ Store.app.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .