1

我正在寻找一种方法来比较两个忽略 TextWrangler 中的空格的文档。虽然 TextWrangler 的界面没有提供该选项,但我发现了这个https://groups.google.com/d/msg/bbedit/ER3VdOf2xOs/IcKi3ccA90oJ

现在这不是一个完全有效的解决方案。虽然这个脚本:

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

有效,它有点不灵活。所以我试图让第二个存根工作:

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

但在这里我得到错误:

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

我在这里做错了什么?

我想补充一点,以下脚本也有效:

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

但这不起作用:

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}

它只是不编译。什么……?

4

1 回答 1

2

这些选项只有 TextWrangler 知道,因此您必须在 TextWrangler tell 块中创建它们。您不能从选项的字符串表示中构建选项,因此如果您想从列表中选择它们,那么您需要从选择的字符串中动态构建它们。看看我是怎么做到的。

祝你好运。

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
于 2015-02-04T16:57:54.583 回答