Deleting contents in your home folder....

Hi guys,

I have a property which has an array of files names. Some are system level and some are home level, which mean its under the library folder of my personal directory. The system files delete successfully, however, the home level files do not. I usually access them like this: ~/Library/Application Support/Software

And then I have a loop which picks each file and deletes it with an rm -R shell script command with administrator privileges.

Am I accessing the home directory the wrong way? Should I use the “~” key?

Please advice.

Thanks and God bless.

Ben.

Also, the “Application Support” folder has to be recognized like this in UNIX “Application\ Support/”, but the way I’m setting it as a string in my property, I cannot do that.

Hi,

you need to escape a POSIX path in a do shell script line, if it contains space characters
for example

quoted form of POSIX path of (path to application support folder from user domain)
--> '/Users/myUser/Library/Application Support/'

Also, you can use two forward slashes.

do shell script "rm -rf ~/Library/Application\\ Support/A\\ FOLDER/" with administrator privileges
do shell script "rm -rf ~/Library/Application\\ Support/A\\ TEST\\ FOLDER/" with administrator privileges and password
do shell script "rm -rf ~/Library/Application\\ Support/Test\\ File.txt" with administrator privileges and password
do shell script "rm -rf ~/Library/Application\\ Support/Test\\ File\\ 2.txt" with administrator privileges and password

Tom

Browser: Safari 525.18
Operating System: Mac OS X (10.4)

A TRY block is good to use too.

try
	do shell script "rm -rf ~/Library/Application\\ Support/A\\ FOLDER/"
	do shell script "rm -rf ~/Library/Application\\ Support/A\\ TEST\\ FOLDER/"
	do shell script "rm -rf ~/Library/Application\\ Support/Test\\ File.txt"
	do shell script "rm -rf ~/Library/Application\\ Support/Test\\ File\\ 2.txt"
end try

Tom

Browser: Firefox 2.0.0.13)
Operating System: Mac OS X (10.4)

Hi Tom,

you’re right, but in your example
if the first folder doesn’t exist but the others, nothing will be deleted :wink:

To make sure that all items will be deleted, you need a try block for each line


try
	do shell script "rm -rf ~/Library/Application\\ Support/A\\ FOLDER/"
end try
try
	do shell script "rm -rf ~/Library/Application\\ Support/A\\ TEST\\ FOLDER/"
end try
try
	do shell script "rm -rf ~/Library/Application\\ Support/Test\\ File.txt"
end try
try
	do shell script "rm -rf ~/Library/Application\\ Support/Test\\ File\\ 2.txt"
end try

or a handler


doErase("~/Library/Application\\ Support/A\\ FOLDER/")
doErase("~/Library/Application\\ Support/A\\ TEST\\ FOLDER/")
doErase("~/Library/Application\\ Support/Test\\ File.txt")
doErase("~/Library/Application\\ Support/Test\\ File\\ 2.txt")


on doErase(E)
	try
		do shell script "rm -rf " & E
	end try
end doErase

Not for me Stefan. It’s strange that it didn’t work for you.

Tom

Browser: Camino
Operating System: Mac OS X (10.4)

Interesting! Given the purpose and documentation for ‘try’ the strange behavior is that it worked for you tom. Are you sure your first folder/file didn’t exist when you tried it?

James, I tried every combination and it always deletes any file or folder that is in the Application Support folder.
I guess it doesn’t work for you either.

Tom

Browser: Camino
Operating System: Mac OS X (10.4)

“any file or folder” means, you have always 4 existing files and folders.
create the same 4 files and folders again, then rename in your script
~/Library/Application\ Support/A\ FOLDER/
with
~/Library/Application\ Support/A\ FOLDER_ONE/

what happens?

Hi Stefan, No, I didn’t. I tried just one folder and then just one file and it works for me.
I tried your test and it still works.

I ran this…

A FOLDER
A FOLDER_ONE
A TEST FOLDER
Test File.txt
Test File 2.txt

and…
A FOLDER
A FOLDER_ONE
Test File.txt
Test File 2.txt

and…
A FOLDER_ONE

and…
Test File.txt

and…
A FOLDER

I can place just ONE file or folder in the Application Support folder and poof… gone.

Tom

P.S. I like your code very much!

Operating System: Mac OS X (10.4)

Hi Tom,

I apologize, you’re absolutely right :slight_smile:
I didn’t realize that the -f flag prevents rm from generating any error message.
My test script was just rm -r

Hi Stefan, It’s very nice of you to let me know. Thanks.
Hey, guess where I just downloaded a cool mount-unmount disk utility :cool: (MountnuoM).

Tom

Browser: Camino 1.6
Operating System: Mac OS X (10.4)