Simple Script Help111

I’m having problems with this script

tell application “Finder”
delete every item in folder “Users:cwru:Documents”
empty trash

end tell

Keep getting error message Can’t get every item of folder “Users:cwru:Documents”

Model: imac
AppleScript: 1.10
Browser: Safari 412
Operating System: Mac OS X (10.4)


This path is invalid:


AppleScript paths begin with the startup disk (barring shortcut tricks) and ends with the file or folder. If you want a path to a folder, then it should end with a colon. e.g.

“Macintosh HD:Users:cwru:Documents:”

an generic way to get a reference to a users Documents folder is:

set user_docs to (path to At Ease documents folder from user domain)


An easier, less ugly way to do this is at the shell level, honestly.

Now, what if we don’t want to empty the trash, but we want to clear out “~/Documents”? Note that this doesn’t take prisoners, so it may be worthwhile to add a confirmation dialog, depending on your use!

	do shell script "/bin/ls $HOME/Documents/"
	-- we run the above ls command so if our string is BAD, or something else goes wrong while looking for ~/Documents, the script breaks HERE instead of the next shell command.
	-- we don't ls with * so we don't nuke script performance.
	do shell script "/bin/rm -rf $HOME/Documents/*"
on error theError
	-- the alert is optional, but the try/on error is NOT OPTIONAL!
	display alert "There was a problem removing the contents of the Documents folder." as critical message theError
end try

Hi Mikey,

You really consider unix less ugly than AppleScript? Beauty is in the eyes of the beholder! :slight_smile:

Have a good day,

set user_docs to (path to At Ease documents folder from user domain)



Yeah, I think the shell is a little cleaner here. :wink:

The path to the current user’s documents folder can simply be:

set user_docs to (path to documents folder)



Yeah, if you can remember what $HOME means and the rest of that unix stuff. :slight_smile: But perhaps the memory is going. As I said, beauty is in the eyes of the beholder.

About the ‘path to’, ‘documents folder’ doesn’t work on my computer running Jaguar and by habit I just use user domain. or you can use:

path to “docs”

but there’s that memory issue again.