当前的 Apple 应用程序编写起来很奇怪。我不使用 rb-appscript,但这里是 Applescript 的工作代码,您应该能够更改以适应和移植:
property dummyList : {"Tyler Durden", "Marla Singer", "Robert Paulson"}
tell application "Pages"
set theDocument to make new document
tell theDocument
set bulletListStyle to ""
set lastListStyle to (count list styles)
repeat with thisListStyle from 1 to lastListStyle
set theListStyle to item thisListStyle of list styles
if name of theListStyle is "Bullet" then
set bulletListStyle to theListStyle
end if
end repeat
repeat with thisItem from 1 to (count dummyList)
set body text to body text & item thisItem of dummyList & return
end repeat
set paraCount to count paragraphs of theDocument
repeat with thisPara from 1 to paraCount
select paragraph thisPara
set theSelection to selection
set paragraph style of theSelection to "Body Bullet"
end repeat
end tell
end tell
本质上,这样做是将每个列表项放在其自己的段落中(这就是列表项的所有意图和目的:带有项目符号的缩进段落),依次选择每个段落,然后将列表段落样式应用于选择。由于某种原因,该paragraph
对象仅返回给定段落的文本,并且其本身不保持任何状态。这不是处理这种情况的最佳方式,但至少所有组件都可以满足您的需求。