有没有办法将 AppleScript 与 Keynote 一起使用,这样我就可以为文本对象激活数字项目符号和列表?

Is there a way to use AppleScript with Keynote, in such a way I can activate Number Bullets and Lists for a text object?

我想自动格式化从 Xcode 复制并粘贴到 Keynote 中的文本字段的 Swift 中的代码。格式确实保留了下来,但我想更改字体大小(我已经完成了)并且我还想添加行号(这可以使用 Bullets 和 Lists of type 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,但我没有找到激活行编号的方法(即激活项目符号和列表中的数字格式。

TI 发现 iWork 中的项目符号和编号是富文本格式的一部分,AppleScript 无法直接访问它。但是,您可以通过 GUI-scripting 稍加努力来完成此操作,例如:

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

它不是很漂亮,但它完成了工作。