For whatever reason, my version was failing when I tried to use the test 'if myChoice is false', i.e. the simple boolean. I wasn't getting consistent results trying to use that weird chevron class notation
{«class fals»:false} either. And for my purposes, I'd rather not have the complication at runtime of allowing multiple selections, so for me the only reason not to use the text coercion would be that my version will fail if the chosen paragraph really *is* the text "false".
As for the try block, this morning I was focused on text, but of course the choose from list line does throw an error if the original clipboard content can't be coerced to text. So in what I've got now, I restored the try block and also placed the line that sets the clipboard text to a variable inside it.
I also adopted Yvan's 'file of first process' to get the active app reference.
Chris, you mentioned the risk of leaving the dialog hanging if the user clicks away or switches applications, but not activating System Events doesn't actually prevent that, does it?
One more remaining flaw is that the original clipboard content is not fully restored if it starts out as data other than plain text but that can be coerced to text. I did a little bit of playing around with storing the uncoerced content to a variable before getting the text, but that failed with a file copied in the Finder and with the styled text of the compiled script itself from AppleScript Editor. Since the multi-clipboard utilities that started the whole thread do exist, there must be some way to restore the full content, at least via ASObjC if not plain AS, but for me I don't think it's worth the time investment to look for a solution.
For reference, here's my current version (which omits Yvan's multiple selection option and Chris's more complete error code):
tell application "System Events"
set frontApp to (file of first process whose frontmost is true) as text
try
set fullClipText to (the clipboard as text)
activate
set myChoice to ((choose from list (paragraphs of fullClipText)) as text)
on error
set myChoice to "false"
end try
end tell
tell application frontApp
activate
if myChoice is not "false" then
set the clipboard to myChoice
tell application "System Events" to keystroke "v" using {command down}
delay 1
set the clipboard to fullClipText
end if
end tell
Michael