applescript - 有没有办法将 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,但我没有找到激活行号的方法(即激活 Bullets 和 Lists.xml 中的数字格式)。
解决方案
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
它不漂亮,但它完成了工作。
推荐阅读
- python-3.x - 计算图子集的最短路径
- java - 通过 JNA 发送用户定义的 Windows 消息
- powershell - 如何在powershell格式表中显示行号或行号
- javascript - 如何修复“查询中接受的正文参数”?
- c# - 在 ListBox 中实现 Selectable 用户控件
- css - 使用其他框架(如 Materialise)时,如何在 Bootstrap Navbar Toggler Icon 处于活动状态时更改其背景颜色?
- odoo - Odoo 模块的菜单根目录未显示
- javascript - 尝试将 .php 页面连接到在与 PHP 页面不同的端口上运行的套接字服务器
- html - 标头 html 错误
- javascript-intellisense - 单击“Tab”时,VSCode 智能感知不起作用