TextEdit Script Wipes out your Desktop -- don't try this; read.

set P to path to desktop folder
tell application "TextEdit"
	set E to make new document at end of documents with properties {name:"Test Format", path:path to desktop folder}
	save E in P
end tell

I may be doing this improperly, but the net effect is pretty bad – you get an error message with two buttons but no matter which of them you choose, your desktop contents disappear. Don’t try this unless you have a recent time machine backup and administrator privileges to restore your desktop.

After you do restore it, “path to desktop folder” will fail until you log out and in again, or wait a minute or so during which it “heals”.

EDIT: Standard Additions can no longer find the “path to desktop folder” though the Finder can. A restart is required to fix that. It doesn’t heal. I’ve repeated this several times.

The bug is in the warning – the buttons don’t work properly. The rest is explained in this response to another thread by Nigel Garvey