script to get clipboard and place into file

This will probably sound very simple, but I’m rather desperate!

I want an Applescript that will grab the contents of the clipboard and place it into a TextEdit file in a particular folder, with some kind of incremental naming so that the file doesn’t get written over.

That’s it, really. I guess it would be good if the thing could handle images using rtfd, but that would be icing on the cake.

Any help with this greatly appreciated.

This should do it for txt:

tell (current date) to set myDate to ((day of it) & "-" & (month of it) & "-" & (year of it) & "**" & (hours of it) & "-" & (minutes of it) & "-" & (seconds of it)) as string

set fileName to ("Clipboard (" & myDate & ")") as string
set fileContainer to (path to desktop) as alias -- insert your folder here

tell application "Finder" to make new file at fileContainer with properties {name:fileName}
set newFile to result as alias

set myData to the clipboard
try
	set OA to open for access newFile with write permission
	write myData to OA
	close access OA
on error
	try
		close access OA
	end try
end try

Hope it helps,
ief2

++Coercion police++ :wink:

both coercions are useless, path to folder returns always an alias


set fileName to ("Clipboard (" & myDate & ")") 
set fileContainer to path to desktop -- insert your folder here

the Finder is not needed to create the file, open for access does this automatically.
This is sufficient


set myDate to do shell script "/bin/date +%d%b%Y_%H%M%S"
set newFile to (path to desktop as text) & "Clipboard (" & myDate & ")"

set myData to the clipboard
try
	set OA to open for access file newFile with write permission
	write myData to OA
	close access OA
on error
	try
		close access file newFile
	end try
end try

Many many thanks for that help! Greatly appreciated!