2015-06-04 5 views
1

Я хочу, чтобы очистить текст от текста TextEdit но только половина работает для менякомпании Apple Script: Очистка TextEdit текст

tell application "TextEdit" 

    set documentText to text of document 1 
    set {oldTID, my text item delimiters} to {my text item delimiters, "Administration"} 
    set textBits to text items of documentText 
    set my text item delimiters to "" 
    set text of document 1 to textBits as text 
    set my text item delimiters to oldTID 

    set documentText to text of document 1 
    set {oldTID, my text item delimiters} to {my text item delimiters, "New Search"} 
    set textBits to text items of documentText 
    set my text item delimiters to "" 
    set text of document 1 to textBits as text 
    set my text item delimiters to oldTID 

    set documentText to text of document 1 
    set {oldTID, my text item delimiters} to {my text item delimiters, "Advanced"} 
    set textBits to text items of documentText 
    set my text item delimiters to "" 
    set text of document 1 to textBits as text 
    set my text item delimiters to oldTID 


    set documentText to text of document 1 
    set {oldTID, my text item delimiters} to {my text item delimiters, "Tips"} 
    set textBits to text items of documentText 
    set my text item delimiters to "" 
    set text of document 1 to textBits as text 
    set my text item delimiters to oldTID 

end tell 

По какой-то причине «Новый поиск» по-прежнему в текстовом документе. Возможно ли в противном случае сохранить текст только от строки 2 до 3?

С уважением.

ответ

1

Несколько разграничителей текстовых элементов могут быть сложными для AppleScript. Попробуйте это:

tell application "TextEdit" to set documentText to text of document 1 

tell application "TextEdit" to set text of document 1 to my RemoveThis(documentText, {"Administration", "New Search", "Advanced", "Tips"}) 

to RemoveThis(txt, termList) 
    repeat with eachTerm in termList 
     set {oldTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, (eachTerm as text)} 
     set textBits to text items of txt 
     set AppleScript's text item delimiters to oldTID 
     set txt to (textBits as text) 
    end repeat 
    return txt 
end RemoveThis 

Таким образом, вы можете определить список терминов, которые будут просеянной через, а не беспокоиться о деталях кодирования.

+0

Это прекрасно работает, также мир должен быть в том же порядке в скрипте, что и в текстовых файлах. Спасибо ! –

+0

Добро пожаловать. Хорошего дня. –

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