TextWrangler:在AppleScript的帮助下比较两个忽略空格的文档



我正在寻找一种方法来比较两个忽略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}

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

这些选项只有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

相关内容

  • 没有找到相关文章

最新更新