2015-02-04 2 views
0

Я искал способ сравнения двух документов, игнорирующих пробелы в TextWrangler. Хотя интерфейс TextWrangler не предоставляет эту опцию, я нашел это https://groups.google.com/d/msg/bbedit/ER3VdOf2xOs/IcKi3ccA90oJTextWrangler: сравнение двух документов, игнорирующих пробелы с помощью AppleScript

Теперь это не было полностью работающим решением. Хотя этот сценарий:

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} 

он просто не компилируется. Что за … ?

ответ

1

Эти параметры известны только для TextWrangler, и поэтому вы должны создать их в блоке tellWrangler 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 
+0

Ваш код работает как очарование! Итак, важный момент, который, как я понимаю, заключается в том, что вы не можете преобразовать строковое представление параметров в объект класса Compare Options of TextWrangler, правильно? Поскольку ваш ответ хороший, я бы хотел его проголосовать, но я не могу, так как мне не хватает репутации, чтобы сделать это, извините! –

Смежные вопросы