-------------------------------------------------------------------------------------------
try
set textFactory to alias ((path to application support from user domain as text) & "BBEdit:Text Filters:Textfactories:UpperCaseAll.textfactory")
set tempDocName to "Temp_Window_" & (do shell script "date \"+%Y-%m-%d_%H%M%S\"")
set workingDocName to "WORKING.txt"
tell application "Mail"
set _sel to selection
if length of _sel = 1 then
set _msg to item 1 of _sel
set _text to content of _msg
end if
end tell
tell application "BBEdit"
# Getting text directly from Mail
set tempDoc to (name of (make new text document with properties {name:tempDocName, bounds:{303, 44, 1617, 1196}, text:_text}))
# Getting text from the clipboard
# set tempDoc to name of (make new text document with properties {name:tempDocName, bounds:{303, 44, 1617, 1196}, text:(get the clipboard)})
apply text factory textFactory to text document tempDoc
delay 0.1 # FAILS WITHOUT THE DELAY.
set _text to text of text document tempDoc
select (first project window whose name starts with workingDocName)
tell text of text document "WORKING.txt"
replace "<!--insert-->" using _text options {starting at top:true}
end tell
end tell
on error e number n
set e to e & return & return & "Num: " & n
tell me to set dDlg to display dialog e with title "ERROR!" buttons {"Cancel", "Copy", "OK"} default button "OK"
if button returned of dDlg = "Copy" then set the clipboard to e
end try
-------------------------------------------------------------------------------------------