Delete all files from desktop except alias ?

I use this to delete files from my desktop

tell application "Finder"
	set target_folder to (desktop) as alias
end tell

tell application "Finder" to delete every file of entire contents of (target_folder)

works great but now I want the alias that I created on my desktop to remain there.

Is that possible ?


Model: mac mini
AppleScript: 2.3
Browser: Safari 535.7
Operating System: Mac OS X (10.6)

try this

tell application “Finder”
set target_folder to (desktop) as alias
delete every document file of (target_folder)
delete every folder of (target_folder)
delete every application file of (target_folder)
end tell

Maybe not the better way to write this but it works.

Hi. You can use a whose clause to filter out unwanted types, and there isn’t a need to coerce the desktop reference to alias.

tell application "Finder" to delete (desktop's files whose class is not alias file)

Entire contents inadvertently captures much more than just the desktop’s files; it includes every file that may happen to live in a folder on the desktop.

thanks guys!