Thanks, Rich.
At first I thought, wow this is complicated. But you make it easy. I shall 
of course have fun when I push beyond simple find/replace, but you've given 
me a great start.
— D

On Monday, May 24, 2021 at 8:44:50 PM UTC-6 [email protected] wrote:

> On 24 May 2021, at 22:37, Christopher Stone wrote:
>
> > On 05/24/2021, at 19:11, Duncan Thorne <[email protected] 
> > <mailto:[email protected]>> wrote:
> >> I'm pretty clueless with Applescript so please bear with me. I want 
> >> to copy text from a Safari table, paste it into a new BBEdit window 
> >> and do some text manipulation, mostly finding and replacing.
> >
> >
> > Hey Duncan,
> >
> > This task is pretty simple if you know how, and a real head-scratcher 
> > if you don't.
> >
> > It's great to be able to record AppleScript, but it often produces 
> > semi-useless results – unless you savvy AppleScript enough to be 
> > able to rewrite the recording and pick out the good bits.
> >
> > I almost never use it, BUT it sometimes comes in really handy when I 
> > just can't figure out the syntax for something.
> >
> > Appended is a script that will:
> >
> > - Copy the selected text in Safari.
> > - Create a new BBEdit document with said text.
> > - Reset the size and position of the new document.
> > - Do one regex-based find/replace on the document.
> > - You can add more replace statements as needed.
>
> This is a good script. Some feedback: as a matter of best practices and 
> future proofing, avoid targeting windows (or elements of them).
>
> "make new text document" will return a reference to the document just 
> created.
>
> The "text" property of a document provides access to the text without 
> going through the windowing system. It's also faster and avoids 
> complications that can arise when the 1:1 relationship between documents 
> and windows is not in effect (as has been the case since BBEdit started 
> supporting multiple documents per window, back whenever that was).
>
> Thus:
>
> set myDoc to make new text document with properties { text: 
> tableContent }
>
> followed by
>
> tell text of myDoc
> -- do the replace in here
> end tell
>
> is recommended.
>
> R.
>
> -- 
> Rich Siegel Bare Bones Software, Inc.
> <[email protected]> <https://www.barebones.com/>
>
> Someday I'll look back on all this and laugh... until they sedate me.
>

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "[email protected]" rather than 
posting here. Follow @bbedit on Twitter: <https://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 view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/2439df04-605d-4a21-af89-f01181144e46n%40googlegroups.com.

Reply via email to