2011-06-20 16 views
1

箇条書きと番号付きリストを含む新しいPagesドキュメントを作成するには、rb-appscriptを使用する必要があります。これを見ると、段落にはlist_styleというプロパティがありますが、そのプロパティを設定する方法を理解するにはrb-appscriptまたはapplescriptには慣れていません。私はASDictionaryによって生成されたドキュメントを読んだことがありますが、AppleScriptに関する知識はそれを理解するにはあまりにも少ないようです。rb-appscriptを使用して箇条書き/番号付きリストをページまたはtexteditに書き込む

ドキュメントに記載されている情報の使い方を理解しているか、またはrb-appscriptを使用してページにリストを書き込んでください。

編集:私はページに固執していない、texteditは実行可能なオプションです。

答えて

2

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 
1

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オブジェクトは、何らかの理由で、指定された段落のテキストを返すだけであり、状態は保持されません。これはこのシナリオを処理する最善の方法ではありませんが、必要なものを得るために少なくともすべてのコンポーネントがあります。

関連する問題