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



我喜欢在 Swift 中自动格式化从 Xcode 复制并粘贴到 Keynote 文本字段中的代码。格式确实被继承了,但我想更改字体大小(我已经这样做了),并且我想进一步添加行号(这可以使用项目符号和编号类型的列表手动完成)。

我写了一个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 脚本轻松完成此操作,如下所示:

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

它并不漂亮,但它可以完成工作。

最新更新