我需要使用rb-appscript创建一个包含项目符号和编号列表的新页面文档。查看一下,我发现段落有一个名为list_style的属性,但我对rb-appscript或applescript还不够熟悉,不知道如何设置该属性。我已经阅读了ASDictionary生成的文档,但我对AppleScript的了解显然太少,无法理解它。
在理解如何使用文档中提供的信息,或者在页面中使用rb-appscript编写列表方面的任何帮助都将不胜感激。
编辑:我不会卡在页面上,textedit也是一个可行的选择。
发布于 2011-06-24 12:07:28
rb-appscript:
require 'rubygems'
require 'appscript'; include Appscript
lst=["a", "b"]
doc = app('Pages').documents[0]
doc.selection.get.paragraph_style.set("Body Bullet")
doc.selection.set(lst.join("\n"))AppleScript:
set lst to {"a", "b"}
set text item delimiters to linefeed
tell application "Pages" to tell document 1
set paragraph style of (get selection) to "Body Bullet"
set selection to (lst as text)
end tell发布于 2011-06-23 23:44:13
当前的苹果应用程序对于脚本来说是很奇怪的。我不使用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这样做的实质是将每个列表项放在它自己的段落中(这就是列表项在所有意图和目的中的含义:缩进的段落和项目符号),依次选择每个list item,然后将list段落样式应用于所选内容。由于某些原因,paragraph对象只返回给定段落的文本,本身并不包含任何状态。这不是处理这种情况的最佳方法,但至少所有组件都可以满足您的需求。
https://stackoverflow.com/questions/6416882
复制相似问题