Есть ли способ использовать AppleScript с Keynote, чтобы я мог активировать Number Bullets and Lists для текстового объекта? - PullRequest
0 голосов
/ 11 июля 2019

Мне бы хотелось автоматизировать форматирование кода в Swift, скопированного из Xcode и вставленного в текстовое поле в Keynote. Формат действительно перенесен, но я хочу изменить размер шрифта (это я и сделал), и далее я хотел бы добавить номера строк (это можно сделать вручную с помощью маркеров и списков типа Number).

Я написал программу AppleScript, которая просто меняет размер шрифта.

Мой код выглядит так:

tell application "Keynote"
    activate
    set ts to the current slide of the front document
    tell ts
        set theTextItem to its first text item
        tell theTextItem
            set the size of its object text to 32
        end tell

    end tell
end tell

Этот код изменяет размер текстового объекта на 32, но я не нашел способа активировать нумерацию строк (то есть активировать формат чисел в пулях и списках.

1 Ответ

1 голос
/ 18 июля 2019

TI показывает, что маркеры и нумерация в iWork являются частью расширенного текстового формата, к которому у AppleScript нет прямого доступа. Тем не менее, вы можете сделать это с помощью GUI-сценариев, приложив немного усилий, например:

tell application "Keynote"
    activate
    tell front document
        tell current slide
            set theTextItem to its second text item
        end tell
        -- this selects the text item
        set selection to theTextItem
    end tell
end tell

tell application "System Events"
    tell process "Keynote"
        tell first window
            -- this makes sure the panel is set to the 'Text' tab
            tell first radio group's radio button "Text"
                if its value = 0 then
                    click
                end if
            end tell
            tell scroll area 1
                -- this finds the correct button, then clicks it to open the popover
                set popoverButton to (first button whose help is "Choose a list style.")
                tell popoverButton
                    click
                    tell first pop over's first scroll area's first table
                        -- this finds the table row in the popover for creating a numbered list
                        -- and selects it. You can substitute in 'Bullet', 'Image', 
                        -- 'Lettered' or any other label in the popover. 
                        select (first row whose first UI element's first text field's value contains "Numbered")
                    end tell
                end tell
            end tell
        end tell
    end tell
end tell

Это не красиво, но оно выполняет свою работу.

...