On May 14, 2014, at 13:32, jgill <[email protected]> wrote:
> I started off by recording this script using Script Debugger using copy and
> paste. Then I switched to using variables.
______________________________________________________________________
Hey Joe,
It's great that BBEdit is so recordable, but it doesn't always produce
straightforward code. From yours it appears you're producing a new document
with text, processing it, and then replacing your designated token in another
document with that newly processed text.
I would prefer to script the excision of text from Mail if possible, and I
would probably run my script from FastScripts (in the Mail context) rather than
from BBEdit's script menu - but your milage may vary.
When I first wrote this it did not properly grab the processed text, and I had
to put in a short delay after the apply text factory action to get it to work
correctly.
Working with front project window or project window 1 can become problematic as
you switch windows, so it's often a good idea to give temp windows a name (see
script).
It's always a good idea to have an error-handler in your scripts.
You'll have to change names and paths to get this to work, and there may be
other tweaks required - but I think it's close.
--
Best Regards,
Chris
-------------------------------------------------------------------------------------------
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
-------------------------------------------------------------------------------------------
--
This is the BBEdit Talk public discussion group. If you have a
feature request or would like to report a problem, please email
"[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].