tell application "System Events"
set frontApp to (file of first process whose frontmost is true) as text
end tell
set fullClipText to (the clipboard as text)
try
# We may select several lines if needed.
set maybe to choose from list (paragraphs of fullClipText) with multiple selections allowed
# returns false if we click Cancel or type Escape
# returns the list of selected lines if we click OK
if maybe is not false then
# Concatenate the selected items with the lineBreak available in the source
if (count maybe) > 1 then
if fullClipText contains (return & linefeed) then
set lineBreak to return & linefeed
else if fullClipText contains linefeed then
set lineBreak to linefeed
else
set lineBreak to return
end if
set maybe to my recolle(maybe, lineBreak)
end if
set the clipboard to maybe
# loop reducing the delay to what is really needed, no less, no more
repeat
delay 0.1
if (the clipboard as text) is maybe then exit repeat
end repeat
tell application frontApp
activate
end tell
tell application "System Events" to keystroke "v" using {command down}
delay 0.2
set the clipboard to fullClipText
end if
end try
#=====
on recolle(l, d)
local oTIDs, t
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set t to "" & l
set AppleScript's text item delimiters to oTIDs
return t
end recolle
#=====