1

I was looking for a way to compare two documents ignoring the whitespace in TextWrangler. While the interface of TextWrangler doesn't provide that option I found this https://groups.google.com/d/msg/bbedit/ER3VdOf2xOs/IcKi3ccA90oJ

Now this was not a fully working solution. While this script:

tell application "TextWrangler"
    compare document 1 against document 2 options ¬
        {case sensitive:true, ignore curly quotes:true, ignore extra spaces:true, ignore leading spaces:true, ignore trailing spaces:true}
end tell

works, it is somewhat inflexible. So I tried to make the second stub working:

set compOpts to {"All Options:false", "case sensitive:true", "ignore curly quotes:true", "ignore extra spaces:true", "ignore leading spaces:true", "ignore trailing spaces:true"}

tell application "TextWrangler"

    tell me to set compOpts to choose from list compOpts ¬
        with title "Compare Front Two Documents" with prompt ¬
        "Select Options" default items (items 2 thru -1 of compOpts) ¬
        multiple selections allowed true ¬
        with empty selection allowed

    display dialog compOpts as string

    set compareOptions to make new Compare Options with properties compOpts

    compare document 1 against document 2 options compareOptions

end tell

but here I get the Error:

error "TextWrangler got an error: Can’t make class Compare Options." number -2710 from Compare Options to class

what I am doing wrong here?

I want to add that the following script also works:

tell application "TextWrangler"
    set compareOptions to ¬
        {case sensitive:true, ignore curly quotes:true, ignore extra spaces:true, ignore leading spaces:true, ignore trailing spaces:true} ¬

    compare document 1 against document 2 options compareOptions

end tell

but this doesn't work:

set compareOptions to {All Options:false, case sensitive:true, ignore curly quotes:true, ignore extra spaces:true, ignore leading spaces:true, ignore trailing spaces:true}

it just doesn't compile. What the … ?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
SqAR.org
  • 557
  • 6
  • 15
  • Since this is the closest question to, "How can I compare two files ignoring whitespace in BBEdit?" (and gave me just enough direction to figure it out) let me leave this command-line incantation here: `bbdiff --ignore-spaces "./path/to/file1.txt" "./path/to/file2.txt"` – ruffin May 27 '21 at 19:30

1 Answers1

2

These options are only known to TextWrangler and as such you'll have to create them in the TextWrangler tell block. You can't build the options from string representations of the options, so if you want to choose them from a list then you'll need to build them dynamically from the chosen strings. Take a look how I did this.

Good luck.

set compOptsList to {"All Options:false", "case sensitive:true", "ignore curly quotes:true", "ignore extra spaces:true", "ignore leading spaces:true", "ignore trailing spaces:true"}

set compOpts to choose from list compOptsList ¬
    with title "Compare Front Two Documents" with prompt ¬
    "Select Options" default items (items 2 thru -1 of compOptsList) ¬
    multiple selections allowed true ¬
    with empty selection allowed

tell application "TextWrangler"
    set chosenOptions to {}

    repeat with i from 1 to count of compOpts
        set thisOption to item i of compOpts

        if thisOption is item 2 of compOptsList then
            set chosenOptions to chosenOptions & {case sensitive:true}
        else if thisOption is item 3 of compOptsList then
            set chosenOptions to chosenOptions & {ignore curly quotes:true}
        else if thisOption is item 4 of compOptsList then
            set chosenOptions to chosenOptions & {ignore extra spaces:true}
        else if thisOption is item 5 of compOptsList then
            set chosenOptions to chosenOptions & {ignore leading spaces:true}
        else if thisOption is item 6 of compOptsList then
            set chosenOptions to chosenOptions & {ignore trailing spaces:true}
        end if
    end repeat

    if chosenOptions is not {} then
        compare document 1 against document 2 options chosenOptions
    else
        compare document 1 against document 2
    end if
end tell
regulus6633
  • 18,848
  • 5
  • 41
  • 49
  • Your code works like a charm! So the important point as I understand is that you can't convert a string representation of options to an object of class Compare Options of TextWrangler, right? Since your answer is good I'd like to vote it up but I can't since I am missing the reputations to do so, sorry! – SqAR.org Feb 23 '15 at 16:46