"Find Difference" on Fragmentary Text

136 views
Skip to first unread message

Jim Leff

unread,
Dec 7, 2024, 8:49:17 AM12/7/24
to BBEdit Talk

I frequently need to "Find Differences" between bits of text, not entire docs. For example, two versions of the same paragraph.

It's a pain to do this via BBEdit. Here's the workflow:

Create new doc
Paste text 1
Save
Create new doc,
Paste text 2
Save
Choose both docs in  "Find Differences"
Trash the two docs.

Has anyone figured out a clever way to script any of this?

I know there are standalone text comparison apps and web apps, but none delivers results in editor markup like BBEdit does. And the web apps have privacy issues. And, anyway, I write in BBEdit so I'd prefer to stick to that environment. 

jj

unread,
Dec 7, 2024, 12:41:20 PM12/7/24
to BBEdit Talk
Jim,


HTH

Jean Jourdain

Jim Leff

unread,
Dec 7, 2024, 5:38:14 PM12/7/24
to BBEdit Talk
Thanks. The scripts seem to require the text to already be distributed to two different docs, so I'm not sure how much time it would save. The doc creation is the tedious part. 

I suppose I'm envisioning a process more like this: invite user to paste text A into a field, then paste text B into another field. Save each snippet to a new doc on desktop, and open Find Diffs pop-up with both docs chosen. I suppose I could delete them afterwards manually, that's not the bottleneck.

Is that realistic do you think?

Rick Gordon

unread,
Dec 7, 2024, 8:35:53 PM12/7/24
to bbe...@googlegroups.com

This page may offer some helpful clues downward from #30:
https://unix.stackexchange.com/questions/582796/using-the-diff-command-to-compare-two-strings

Rick Gordon


From: Jim Leff <jame...@gmail.com>
To: BBEdit Talk <bbe...@googlegroups.com>
Date: Sat, Dec 7, 2024 3:26:05PM -0700
Subject: "Find Difference" on Fragmentary Text

Jim Leff

unread,
Dec 7, 2024, 9:55:32 PM12/7/24
to BBEdit Talk
Rick, thanks, but I got ChatGPT to create the script for me. Here it is. It requests the two snippets and transfers them to docs on desktop (and  opens desktop folder so you can delete them), then opens Find Differences with the snippets properly selected (stealing from JJ's work!).

It runs well but requires BBEdit's Command Line Tools and some permissions tweaks:

To run the streamlined BBEdit script without issues, here is a comprehensive list of any necessary system resets, preferences, and settings adjustments:

1. Install BBEdit Command-Line Tools
  • Required: The script uses the bbdiff command from BBEdit's command-line tools.
  • How to Install:
    • Open BBEdit.
    • Go to BBEdit > Install Command Line Tools in the menu bar.
  • Verify installation by running this in Terminal:
    bash
    Copy code
    which bbdiff
    It should return a path like /usr/local/bin/bbdiff.

2. Grant Automation Permissions
  • Why: macOS requires explicit approval for apps to send Apple Events to each other.
  • How:
    • Go to System Settings > Privacy & Security > Automation.
    • Ensure BBEdit is listed and allowed to interact with the following:
      • Script Editor (or the tool used to run the script, e.g., Terminal).
  • If not listed, manually add these tools to Full Disk Access (next step).

3. Grant Full Disk Access (If Needed)
  • Why: macOS may block file writes or other operations without explicit approval.
  • How:
    • Go to System Settings > Privacy & Security > Full Disk Access.
    • Add:
      • BBEdit
      • Script Editor (or the tool running the script, e.g., Terminal).
    • Enable the toggles.

4. Optional: Reset Automation Permissions
  • When to Reset:
    • If BBEdit or related tools are behaving unpredictably.
  • How to Reset:
    • Open Terminal and run:
      bash
      Copy code
      tccutil reset AppleEvents
    • This clears all AppleEvents permissions. You'll need to re-grant permissions to BBEdit and other tools (steps 2 and 3).

5. Avoid Common File Path Issues
  • Why/tmp paths sometimes cause issues on macOS.
  • Resolution: The script uses /private/tmp to ensure compatibility with macOS's internal handling of temporary paths.

Final Checklist for Smooth Use
  1. Install BBEdit's Command Line Tools.
  2. Grant Automation Permissions for BBEdit and Script Editor.
  3. Add Full Disk Access Permissions for BBEdit and Script Editor.
  4. Optional: Run tccutil reset AppleEvents if automation permissions seem broken.

Bruce Van Allen

unread,
Dec 8, 2024, 4:48:59 AM12/8/24
to bbe...@googlegroups.com
One more improvement would be to permanently dedicate two files for this use. Locate them in some safe place - not temp files - named so you’ll remember not to accidentally delete later, e.g., “CompareDoc1” & “CompareDoc2”. Then hard-code them with paths in your script. Eliminates all the steps related to creating files. The script can overwrite the previous comparison’s text fragments each time it’s called, or maybe just close the files without saving, leaving the files on disk always blank.

HTH,

> On Dec 7, 2024, at 6:55 PM, Jim Leff <jame...@gmail.com> wrote:
>
> Rick, thanks, but I got ChatGPT to create the script for me. Here it is. It requests the two snippets and transfers them to docs on desktop (and opens desktop folder so you can delete them), then opens Find Differences with the snippets properly selected (stealing from JJ's work!).
>
> It runs well but requires BBEdit's Command Line Tools and some permissions tweaks:
>

— Bruce

_bruce__van_allen__santa_cruz_ca_


Bruce Van Allen

unread,
Dec 8, 2024, 4:58:35 AM12/8/24
to bbe...@googlegroups.com
Meant to also say: I know - hard coding a path, ew! One alternative if you have a BBEdit Project involving multiple files you’ll be working on for a while - I have a bunch of those - you could install a project's own two compare docs in the project, and the script could reference then via the current Project, rather than hard-coding their paths. OTOH, hard-coding on your regular work machine where this need will arise is not necessarily evil. And the location could be fairly universal, such as in the /Users/Shared/ directory.
> --
> This is the BBEdit Talk public discussion group. If you have a feature request or believe that the application isn't working correctly, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Mastodon: <https://mastodon.social/@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 bbedit+un...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/bbedit/6DA0A5D7-8E0D-4FE0-804B-E62FC8E536DE%40cruzio.com.

jj

unread,
Dec 8, 2024, 5:54:30 AM12/8/24
to BBEdit Talk
Given that you are comparing two parts of the same document, I updates the scripts so they will work between a document's window and the same document's  Additional Window.

Open your source document as an Additional Window and select another part of the document.
As far as the two selections don't overlap, this should work.

HTH
Message has been deleted

Jim Leff

unread,
Dec 8, 2024, 12:27:03 PM12/8/24
to BBEdit Talk
Bruce,

Agreed. Makes sense. Though the notion runs counter to everything They tried to teach us all these years!

thanks,

JIM

Roger Moffat

unread,
Dec 9, 2024, 9:45:20 AM12/9/24
to bbe...@googlegroups.com


On Dec 7, 2024, at 5:26 PM, Jim Leff <jame...@gmail.com> wrote:

I suppose I'm envisioning a process more like this: invite user to paste text A into a field, then paste text B into another field. Save each snippet to a new doc on desktop, and open Find Diffs pop-up with both docs chosen. I suppose I could delete them afterwards manually, that's not the bottleneck.

When I do things like this I don’t see any need to save the 2 snippets before comparing them.

Then when done just close and not save 2 untitled windows.

Roger

Kevin

unread,
Dec 9, 2024, 9:45:20 AM12/9/24
to BBEdit Talk
Sorry if this is late to the discussion, but I often use the "Find Differences -> Compare Two Front Windows" command. It doesn't require you to save the documents at all. You can just paste text into two new document windows and run it. Hope that helps.

Jim Leff

unread,
Dec 9, 2024, 11:59:20 AM12/9/24
to BBEdit Talk
Roger and Kevin, 

Yeah, I noticed via JJ's script that unsaved documents work. I guess this is thanks to the broad overhaul to treatment of unsaved docs a few versions ago.

But this presents the hairy prospect of selecting Untitled Document 1839 and Untitled Document 1147 for comparison. Yikes!

And if that part is scripted, with each snippet going into an unsaved doc, that creates problems finding (and safely retaining) the changed one if I applied changes from one doc to the other. JJ anticipated this issue via a second script, but that's a bit cumbersome for me.

I think Bruce's down-n-dirty  solution works best: Save two docs to a remote folder and have the script overwrite those docs each time it runs. If I do apply a change to one, I know where to grab that doc (at least until the next script execution overwrites it). If not, I don't have to close windows or delete files.

Jim Leff

unread,
Dec 9, 2024, 12:05:35 PM12/9/24
to BBEdit Talk
Whoops, Kevin, I see now that I was talking past you in my last posting (addressed to you and Roger).  I get what you're saying now. 

I've been ignoring that option in the past because the docs used to need to be saved. Since that's no longer an issue, this is indeed a useful alternative when comparing entire docs (rather than than snippets). 

Issues: 

1. With different windows and projects open, it's tricky to determine the *second* frontmost window! 

2. This only works with snippets of text if I open two new windows and paste into both (and remember to close them when done), so I think the script's faster for that use case.

Reply all
Reply to author
Forward
0 new messages