I'm a little stumped. I have an Applescript which successfully processes RTF on the clipboard into Markdown text, and can do... something with it, either save it into a temp file or store the results in a string in Applescript. The problem is getting it into the BBEdit document.

What I want to do is make it behave like the Paste command: either insert the new Markdown text at the insertion point, or replace the selected text if there's a selection. But so far I've had no luck in figuring out how to do this -- if there's a simple "insert text 'foo'" command, I haven't found it.

Here's the script as it is. (As you can see, it relies on an HTML-to-Markdown script that's on my local system -- it'd be nice to be able to move a copy of that script into a BBEdit 10 package, but one thing at a time, right?) I can get the result text as "myText," but the only thing I've been able to successfully do is create a new document and set the text to that variable -- workable, but not what I actually want. I need to figure out what happens at "do something here" to let me either replace a selection or just insert the text.

set theRTF to the clipboard as «class RTF »
set theUserFolder to (path to home folder as text)
set thePath to "tmp:temp.rtf"
set newFile to open for access file thePath with write permission
write theRTF to newFile
close access newFile
set myText to do shell script "textutil -stdout -convert html /tmp/temp.rtf | /usr/local/bin/html2text"

tell application "BBEdit"
        -- do something here!
replace "\\r\\r\\r" using "\\r\\r" searching in text 1 of front document options {search mode:grep, starting at top:true, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}
end tell

--
Watts Martin <lay...@gmail.com>

--
You received this message because you are subscribed to the "BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem, please email "supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

Reply via email to