AppleScript - поиск и замена в стиле основных изменений - PullRequest
0 голосов
/ 23 февраля 2019

Я собрал воедино приведенный ниже сценарий, чтобы установить маркер под названием «говорящие точки» в третьем абзаце «Заметки докладчика» в презентации Keynote, а затем заменил этот маркер записанными заметками из OmniOutliner.Каждый ряд OmniOutliner соответствует номеру слайда (строка 1 для слайда 1, строка 2 для слайда 2 и т. Д.).

Проблема в том, что, когда код заменяет маркер «alkingPoints », он меняет стиль всей заметки докладчика и изменяется в соответствии со стилем первой строки.Как я могу изменить свой сценарий, чтобы сохранить стиль каждого абзаца?

Спасибо!

tell application "OmniOutliner"
    activate
    try
        if not (exists document 1) then error number 10000

        display dialog "This script will replace the marker (talkingPoints) within the presenter notes of the active slides of the frontmost Keynote presentation, with the contents of this outline." & return & return & "The contents of each row will replace the marker (talkingPoints) within the presenter notes of a corresponding Keynote slide." with icon 1

        tell application "Keynote"
            activate
            if not (exists document 1) then error number 10001

            tell front document
                set the slideCount to the count of (slides whose skipped is false)
            end tell
        end tell

        tell the front document
            set theseOutlinerNotes to the topic of every row
        end tell

        if the (count of theseOutlinerNotes) is greater than the slideCount then
            error number 10002
        else if the (count of theseOutlinerNotes) is less than the slideCount then
            error number 10003
        end if
    on error errorMessage number errorNumber
        if errorNumber is 10000 then
            set errorMessage to "No document is open."
        else if errorNumber is 10001 then
            set errorMessage to "No presentation is open."
        else if errorNumber is 10002 then
            set errorMessage to ¬
                "There are more rows in this document than there are active slides in the presentation."
        else if errorNumber is 10003 then
            set errorMessage to ¬
                "There are fewer rows in this document than there are active slides in the presentation."
        end if
        if errorNumber is not -128 then
            display alert "PREPARATION ERROR" message errorMessage
        end if
        error number -128
    end try
end tell

set targetMarker to "talkingPoints"

tell application "Keynote"
    tell the front document
        repeat with i from 1 to the count of slides
            tell slide i
                tell presenter notes
                    set (the third paragraph) to ¬
                        "talkingPoints"
                end tell
                if presenter notes contains targetMarker then
                    set targetNotes to (presenter notes as string)
                    tell application "System Events"
                        set AppleScript's text item delimiters to targetMarker
                        set presenterNoteParsed to every text item of targetNotes
                        set AppleScript's text item delimiters to ""
                    end tell
                    set presenterString to (item 1 of presenterNoteParsed) & (item i of theseOutlinerNotes) & (item 2 of presenterNoteParsed)
                    set presenter notes to presenterString
                end if
            end tell
        end repeat
    end tell
end tell
...