スクリプト可能なMacアプリでText Suite
を使用しようとしています。Cocoa Scripting:テキストスイートの統合
私がCocoa Scripting Guideで見つけた小さなドキュメントは、NSTextStorage
を使用することを示しています。しかし、Sdefとコーディング面の両方で、残りの仕組みをどのように設定する必要があるのかは説明していません。
特に、私は、テキストスイートをより豊富なコマンドで使用するときと、そうでないときにスクリプト定義をどのように伝えるのかと思います。私が見ている問題は、Text Suiteがtext
という名前の独自のタイプを宣言していることです。しかし、これは既にプレーンテキストにも使われている定義済みの型です。
私は、Sdefエディタのテキストセレクタで、要素のプロパティと、同じ型のSdefに2つの "text"を選択することになります。意味私は文字スイートをサポートするテキストを扱うプロパティとそうでないものとの間でSdefを区別することはできません。たとえ自分のコードが常にNSTextStorage
を使用するとは限りません。
私はすべてのスクリプト可能なプロパティをクラスNSTextStorage
のオブジェクトに格納する必要があるということですか?それ以外の場合、ユーザーは任意のテキストプロパティで拡張Text Suiteコマンドを使用することを期待できますが、NSTextStorage
の代わりにNSString
を使用すると実行時エラーが発生します。
しかし、アプリケーションの名前のように単純なプレーンテキスト文字列を返すだけの単純なプロパティの場合、Text Suiteをサポートするのは難しいでしょうか?
これはどうすればいいですか?私がリッチテキストサポートの価値があると思われるプロパティについてのみNSTextStorage
を使用しているため、ユーザーがText Suiteを使用できるときにはユーザーに理解させてもらいますか?どのように他の人がこれを解決するのですか
更新
が、私は単に私のSdef(私はSdefエディタがそのファイルのサブメニューの下に「NSTextSuite」として提供しています1を使用しています)にテキストSuiteを追加するときというtext
を返すすべてのプロパティが判明(エラー-10000を引き起こす)動作を停止します。 Text Suiteのエントリーを他のアプリのエントリーと比較したところ、明らかな違いはありません。
テキストスイートを追加すると、「テキスト」タイプのプロパティを持つすべてのプロパティが破損するのはなぜですか?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary title="Demo Terminology">
<suite name="Demo Suite" code="Demo" description="Demo suite">
<class name="application" code="capp" description="The application's top-level scripting object.">
<cocoa class="NSApplication"/>
<property name="demo text" code="DeTx" description="A text prop for testing" type="text">
<cocoa key="testText"/>
</property>
</class>
</suite>
<suite name="Text Suite" code="????" description="A set of basic classes for text processing.">
<cocoa name="NSTextSuite"/>
<class name="text" code="ctxt" description="Rich (styled) text" plural="text">
<cocoa class="NSTextStorage"/>
<element type="paragraph">
<cocoa key="paragraphs"/>
</element>
<element type="word">
<cocoa key="words"/>
</element>
<element type="character">
<cocoa key="characters"/>
</element>
<element type="attribute run">
<cocoa key="attributeRuns"/>
</element>
<element type="attachment">
<cocoa key="attachments"/>
</element>
<property name="color" code="colr" description="The color of the first character." type="color">
<cocoa key="foregroundColor"/>
</property>
<property name="font" code="font" description="The name of the font of the first character." type="text">
<cocoa key="fontName"/>
</property>
<property name="size" code="ptsz" description="The size in points of the first character." type="number">
<cocoa key="fontSize"/>
</property>
</class>
<class name="attachment" code="atts" description="Represents an inline text attachment. This class is used mainly for make commands." inherits="text">
<cocoa class="NSAttachmentTextStorage"/>
<!-- This property should be deprecated like all the other path-centric properties, and replaced with a type="file" property. -->
<property name="file name" code="atfn" description="The path to the file for the attachment" type="text">
<cocoa key="filename"/>
</property>
</class>
<class name="paragraph" code="cpar" description="This subdivides the text into paragraphs." inherits="text">
<cocoa class="NSTextStorage"/>
</class>
<class name="word" code="cwor" description="This subdivides the text into words." inherits="text">
<cocoa class="NSTextStorage"/>
</class>
<class name="character" code="cha " description="This subdivides the text into characters." inherits="text">
<cocoa class="NSTextStorage"/>
</class>
<class name="attribute run" code="catr" description="This subdivides the text into chunks that all have the same attributes." inherits="text">
<cocoa class="NSTextStorage"/>
</class>
</suite>
<suite name="Standard Suite" code="????" description="Common classes and commands for most applications.">
<cocoa name="NSCoreSuite"/>
<class name="color" code="colr" description="A color.">
<cocoa class="NSColor"/>
</class>
</suite>
</dictionary>
エラー-10000になります。このスクリプトを実行する:あなたは私がやっているものを見ることができるように、次は何
は省略Sdefです
tell application "Demo"
demo text
end tell
私は「削除した場合Text Suite "をSdefから削除すると、コードはエラーなく実行されます。
右。あなたが提案するのは、現代のSketchアプリケーションサンプルが使用するものと、私が動作することがわかったものです。 Sdefエディタが提供するSdefは、私の質問で見られるもので、明らかに悪い選択です。 –
Thomas、コードラインの1つが正しく字下げされていないとわかったので、私は自分の答えを修正しました。私は今までSdef Editiorを使っていませんでした。私は単純な古いテキストXMLエディタを使い、DTDを使ってXMLを検証します。 –