首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用rb-appscript在pages或textedit中编写项目符号/编号列表

使用rb-appscript在pages或textedit中编写项目符号/编号列表
EN

Stack Overflow用户
提问于 2011-06-21 04:11:34
回答 2查看 467关注 0票数 1

我需要使用rb-appscript创建一个包含项目符号和编号列表的新页面文档。查看一下,我发现段落有一个名为list_style的属性,但我对rb-appscript或applescript还不够熟悉,不知道如何设置该属性。我已经阅读了ASDictionary生成的文档,但我对AppleScript的了解显然太少,无法理解它。

在理解如何使用文档中提供的信息,或者在页面中使用rb-appscript编写列表方面的任何帮助都将不胜感激。

编辑:我不会卡在页面上,textedit也是一个可行的选择。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-06-24 12:07:28

rb-appscript:

代码语言:javascript
复制
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:

代码语言:javascript
复制
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
票数 2
EN

Stack Overflow用户

发布于 2011-06-23 23:44:13

当前的苹果应用程序对于脚本来说是很奇怪的。我不使用rb-appscript,但这里是Applescript的工作代码,您应该能够根据口味和端口进行更改:

代码语言:javascript
复制
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对象只返回给定段落的文本,本身并不包含任何状态。这不是处理这种情况的最佳方法,但至少所有组件都可以满足您的需求。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6416882

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档