delete file from desktop


Since i’m quite new to applescript, this might be an easy one…i hope…

I have a file on the desktop that i want to delete. But the problem is that this script should work on any machine. So i need to use dynamic file paths. This is what i got:

tell application "Finder"
	set file_path to ((path to desktop folder) & "invoice.pdf")
end tell

So i have the file path (altough…I think) , but what do i type next to the delete step?
Can’t get it right…:frowning:


The ‘delete’ command requires an alias, or file specification to identify what item(s) to delete.

Your first line (set file_path to…) creates a string defining the path to the file in question (e.g. “Macintosh HD: Desktop:invoice.pdf”), so you need to convert (or “coerce”) this string to a file.

This is easily done by tell applescript to interpret file_path as a file:

delete file file_path

Hi Camelot and thnx for your reply:)

Reading your response makes me this script:

tell application "Finder"
	set file_path to ((path to desktop folder) & "factuur.pdf")
	delete file file_name
end tell

The problem is that I still get an error:

Finder got an error: Can't make some data into the expected type.

And then it ends up with selecting the whole delete line in script composer.

It’s strange, because i’am putting data into the file_path variable, but applescript can’t do anything with it?


Jeffery, try it like this…
[This script was automatically tagged for color coded syntax by Script to Markup Code]

This might work too.

tell application "Finder" to delete file "invoice.pdf" of desktop

– Rob

tell application "Finder" to delete document file "MimeText" of desktop

is what worked for me. I don’t know if the word “document” is necessary, but it was in a result the Finder gave me, so I used it, and it works.