How to detect whether clipboard has text or graphic etc.?

I’m writing a script that that writes the contents of the clipboard to a text file (and have already received terrific help in another thread). Here’s another question that I can’t find an easy to, and I will be grateful for anyy thanks help.

If the clipboard contains a graphic, instead of text, then my script writes an empty file. And if the clipboard contains (for example) an alias, it writes the name of the alias into the file.

Is there a way I can detect whether or not the clipboard contains text, and alert the user, or do something else, if the clipboard does NOT contain text?

Many thanks for any help you can give with this obscure problem.


the clipboard can be coerced to text.
If there are no text classes, the coercion fails and an error will be thrown.


on checkClipboardContainsText()
		the clipboard as text
		return true
	on error
		return false
	end try
end checkClipboardContainsText

Perfect. Thank you, Stefan!