Adobe InCopy CS6 desktop publishing software Scripting Guide
Below you will find brief information for desktop publishing software InCopy CS6. InCopy CS6 is a collaborative text editing application designed to be used with Adobe InDesign. You can use it to track changes, add editorial annotations, and fit copy to the space allocated in the layout. Because InCopy and InDesign use the same text composition engine, you get identical typesetting results when you place copy in your layout.
Advertisement
Advertisement
ADOBE
®
INCOPY
®
CS6
ADOBE INCOPY CS6
スクリプティングガイド:
APPLESCRIPT
2012 Adobe Systems Incorporated. All rights reserved.
Adobe® InCopy® CS6 スクリプティングガイド: AppleScript
CS6
更新
ドキュメントの更新ステータス
(ドキュメント全体。各章の更新ステータスについては、それぞれの章を参照してください)
ドキュメント全体で CS5 から CS6 への変更およびバージョン 7.0 から 8.0 への変更。
If this guide is distributed with software that includes an end user agreement, this guide, as well as the software described in it, is furnished under license and may be used or copied only in accordance with the terms of such license. Except as permitted by any such license, no part of this guide may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, recording, or otherwise, without the prior written permission of Adobe Systems Incorporated. Please note that the content in this guide is protected under copyright law even if it is not distributed with software that includes an end user license agreement.
The content of this guide is furnished for informational use only, is subject to change without notice, and should not be construed as a commitment by Adobe Systems Incorporated. Adobe Systems Incorporated assumes no responsibility or liability for any errors or inaccuracies that may appear in the informational content contained in this guide.
Please remember that existing artwork or images that you may want to include in your project may be protected under copyright law.
The unauthorized incorporation of such material into your new work could be a violation of the rights of the copyright owner. Please be sure to obtain any permission required from the copyright owner.
Any references to company names in sample templates are for demonstration purposes only and are not intended to refer to any actual organization.
Adobe, the Adobe logo, Creative Suite, InCopy, InDesign, Illustrator, and Photoshop are registered trademarks or trademarks of Adobe
Systems Incorporated in the United States and/or other countries. Microsoft and Windows are registered trademarks or trademarks of
Microsoft Corporation in the United States and/or other countries. Apple and Mac OS are trademarks of Apple Computer,
Incorporated, registered in the United States and other countries. All other trademarks are the property of their respective owners.
Adobe Systems Incorporated, 345 Park Avenue, San Jose, California 95110, USA. Notice to U.S. Government End Users. The Software and Documentation are “Commercial Items,” as that term is defined at 48 C.F.R. §2.101, consisting of “Commercial Computer
Software” and “Commercial Computer Software Documentation,” as such terms are used in 48 C.F.R. §12.212 or 48 C.F.R. §227.7202, as applicable. Consistent with 48 C.F.R. §12.212 or 48 C.F.R. §§227.7202-1 through 227.7202-4, as applicable, the Commercial Computer
Software and Commercial Computer Software Documentation are being licensed to U.S. Government end users (a) only as
Commercial Items and (b) with only those rights as are granted to all other end users pursuant to the terms and conditions herein.
Unpublished-rights reserved under the copyright laws of the United States. Adobe Systems Incorporated, 345 Park Avenue, San Jose,
CA 95110-2704, USA. For U.S. Government End Users, Adobe agrees to comply with all applicable equal opportunity laws including, if appropriate, the provisions of Executive Order 11246, as amended, Section 402 of the Vietnam Era Veterans Readjustment Assistance
Act of 1974 (38 USC 4212), and Section 503 of the Rehabilitation Act of 1973, as amended, and the regulations at 41 CFR Parts 60-1 through 60-60, 60-250, and 60-741. The affirmative action clause and regulations contained in the preceding sentence shall be incorporated by reference.
目次
3
目次
4
目次
5
アサインされたストーリーのプロパティに対する繰り返し処理 . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
目次
6
1
概要
章の更新ステータス
CS6
変更なし
このマニュアルでは、次の作業を行う方法について説明します。
Adobe® InCopy® のスクリプティング環境の操作
高度なスクリプティング機能の使用
InCopy ドキュメントのテキストや書式の操作(テキストの検索と変更など)
ダイアログボックスなどのユーザーインターフェイスアイテムの作成
メニューのカスタマイズや追加と、メニューアクションの作成
ユーザーインターフェイスのイベントに対する応答
XML の操作(XML 要素の作成、XML の読み込み、レイアウトへの XML 要素の追加など)
このマニュアルに掲載されているスクリプトの使用方法
このマニュアルに掲載されているスクリプトのほとんどは、完全なスクリプトではありません。 このマニュ
アルの説明内容に関連するスクリプトから特定部分のみを抜粋した、断片的なスクリプトです。 このマニュ
アルに掲載されているスクリプトの行をコピーして、スクリプトエディタに貼り付けることができますが、
スクリプトを実行するには、さらに編集が必要になります。 また、このマニュアルからコピーしたスクリプ
さい。このような文字が含まれていると、スクリプトを正常に実行できません。
このマニュアルに掲載されているすべてのスクリプトの Zip アーカイブは、InCopy のスクリプティングホー
ムページ( http://www.adobe.com/jp/products/incopy/scripting/index.html
)で入手できます。
ウンロードして展開したら、該当するスクリプト言語に対応するフォルダーを InCopy フォルダー内の Scripts
フォルダーの下にある Scripts Panel フォルダーに移動します。 これで、InCopy のスクリプトパネルからスクリ
プトを実行できます。
スクリプトの構造について
サンプルスクリプトはすべて、main、mySetup、mySnippet、myTeardown(ハンドラー)などの共通のテン
プレートを使用して記述されています。 この記述方式は、自動化テストとパブリケーションを簡略化するた
めのものです。通常はスクリプトをこのように構築する必要はありません。 スクリプト作成者の関心を引く
と思われるスクリプトの断片は、mySnippet ハンドラー内に記述されています。
詳細情報
InCopy スクリプティングに関するユーザーフォーラム( http://www.adobeforums.com
)でも、InCopy スクリ
プティングに関する情報が入手できます。 このフォーラムでは、質問をしたり、質問に答えたり、新たに作
成したスクリプトを別のユーザーと共有したりできます。 このフォーラムでは、多数のサンプルスクリプト
が提供されています。
7
第 1 章 概要
InCopy について 8
InCopy について
InCopy は、Adobe InDesign® との統合利用を目的に開発された共同作業用のテキスト編集アプリケーションで
す。 InCopy では、変更をトラックしたり、編集上の注釈を追加したり、原稿用のスペースに合わせて原稿を
はめ込んだりすることができます。 InCopy と InDesign は同じテキスト組版エンジンを使用しているので、レ
イアウトに原稿をはめ込んだときの組版結果はまったく同じになります。
や新聞、企業出版物を共同で制作し、テキストの編集とレイアウトの編集を並行して進めることができます。
対象となるユーザーは、編集者、ライター、校正者、原稿の編集者、原稿の加工業者です。
InCopy は、多くのパネルやパレットを InDesign と共有していますが、独自のユーザーインターフェイス項目
も搭載しています。
InCopy ファイルと InDesign ファイルの関係
InCopy ファイルと InDesign ファイルの関係は重要です。これは、出版ワークフローにおける作業の分担は、
1 つの素材の大部分を両方のアプリケーションで開いて変更する場合に発生するためです。
InCopy からの一般的な書き出し方法は、2 種類あります。
(IDML ベースの)ICML ファイルを書き出すことができます。
(INX ベースの)INCX ファイルを書き出すことができます。
InDesign からの一般的な書き出し方法で、InCopy との連携を伴うものは、2 種類あります。
InCopy ファイルとして InDesign から書き出されたストーリーは、XML ファイルまたは XML ストリームで
す(この機能は、InDesign に読み込まれる InCopyExport と InCopyWorkflow のプラグインによって提供さ
である、ページの形状が一切含まれていない、XML ファイルまたは XML ストリーム内のデータは
InDesign や InCopy だけでなく検索エンジンやデータベースツールなどでも使用できるといった実用的な
特徴があります。
記事内の各グループ(見出し、署名欄、原稿、グラフィック、キャプションなど)を書き出すこともで
きます。 InDesign および InCopy では、各グループの作成をアサインファイルでサポートしています。ア
サインファイルは、その他のファイルをトラックする補助ファイルを追加することで、ファイル管理を
行います。 実際には、アサインとは、依頼作業(例えば、原稿の編集、レイアウト、原稿の作成など)
のために 1 人の人間に割り当てられる一連のファイルです。 アサインに含まれるすべてのストーリーは、
保持されます。 InDesign では、アサインに書き出すことによって、特定のストーリー一式を書き出すこと
ができます。 InCopy で、アサインに含まれているすべてのストーリーを同時に(1 つの単位として)開き
を参照してください。
ストーリー
InDesign ドキュメントは、書き出し時に、同じ数の InCopy ドキュメントにモジュール化することができま
クパネル、または InCopy のアサインパレットのアサインファイルで確認できます。
InCopy では、InDesign ドキュメントへのリンクが存在していて関連付けが行われていても、リンクは維持さ
ストーリーは、XML で構造化することができます。 つまり、XML データの中に XML データを含めることがで
いる外部の構造内に、ストーリーの未加工テキストを含めることができます。
第 1 章 概要
InCopy ファイルと InDesign ファイルの関係 9
XML で書き出すことができます。
ICML または INCX ファイルには、InCopy データとマークアップテキストの両方を含めることができます。
ファイルを XML データで書き出した場合は、InCopy 特有のデータが取り除かれ、スタイルの設定に関する情
報以外のマークアップ記述が残ります。
ページの形状
する必要があります。 InCopy では、必要な場合に InDesign ドキュメントを開いて、デザイン情報や書き出さ
れたストーリーへのリンクを抽出することができます。 InCopy 内でページの形状が必要になる場合、アサイ
ンファイルにページの形状を含めて提供することができます。
メタデータ
Adobe Extensible Metadata Platform(XMP)は、メタデータを作成、変換、管理するための実用的な方法を提
供しています。 InCopy ファイルでは、XMP がサポートされています。
XMP データを表示するために、InDesign ではファイル/ファイル情報のコマンドが用意されているように、
は、書き出し時に XMP データをそのまま残しておくことも、取り除くこともできます。
サードパーティーソフトウェア開発者によってストーリーに追加されたメタデータは、InDesign ドキュメン
トに組み込むときにそのまま保持されます。 追加されたメタデータは、InDesign 内で表示できるだけでなく
(リンクパネルのメニューにあるファイル情報ダイアログボックス)、InCopy 内でも表示できます。 さらに、
サードパーティーソフトウェア開発者は、メタデータをカスタムユーザーインターフェイスで表示する機能
を InDesign に追加することもできます。
サービスプロバイダーがメタデータの内容を InCopy ファイルに追加するための拡張のポイントがあります。
を参照してください。
ドキュメントモデル
トを使用することもできますが、デフォルトのドキュメントタイプにはなっていません。
InDesign と InCopy のいずれも、基本のドキュメントは常にデータベースです。ただし、InCopy では、このド
キュメントが不完全なドキュメントになることがあります。 InDesign では、通常、主なドキュメントは開い
ている InDesign ファイルですが、開いている INX または IDML ファイルになることもあります。通常、INX ま
たは IDML ファイルは、保存されていない InDesign ドキュメントのように見えます。
込まれている InCopy ストーリー(またはプレーンテキストや RTF テキスト)があります。 また、IDML や INX
ベースのアサインファイルもあります。これらのアサインファイルには、XML ファイルに保存されている
デルのプラグインセットに対応しており、時間とともに変更に合わせたバージョンアップが重ねられていま
により、ドキュメントをアプリケーション間で移動しても、ほとんど同様に表示することが可能になります。
ユーザーインターフェイスの違い
InDesign と InCopy は多くのパネルを共有していますが、InCopy は小型のセットで、画面の上、左、下の境界
に補助的なツールバーが表示されます。 また、InCopy の多くのパネルは、このツールバーにドッキングさせ
ることができます。ドッキングさせると、パネルは小型化されますが、常に表示されるようになります。
第 1 章 概要 設計とアーキテクチャ 10
また、InCopy には複数のビューによるカスタムウィンドウレイアウトが用意されており、メインウィンドウ
にゲラビュー、ストーリービュー、レイアウトビューの 3 つのタブがあります。 レイアウトビューは InDesign
ウィンドウのビューです。 ゲラビューとストーリービューは、単なるストーリーエディターのビューです。
ゲラビューでは正確な行末が適用され、ストーリービューでは適用されません。
設計とアーキテクチャ
ストーリーとファイルの関係
示しており、特に InDesign 以外でファイルの編集が必要な場合に適した選択です。
ICML 形式
各 InCopy ファイルやストリームは、XML 形式で記述されています。 この利点は、InCopy ファイルを簡単に解
析できることと、あらゆるテキストエディターで開けることです。
INCX 形式
が、INCX ベースのワークフローを引き続きサポートする場合に使用できます。
ドキュメントの操作
InCopy では、ドキュメントの操作(ファイルの操作)のデフォルト実装が提供されています(例えば、新
ファイルの操作は、1 つのプラグイン(InCopyFileActions)にソースコード形式で含まれています。 ソフト
ウェア開発者やシステムインテグレーターが、この部分を独自の実装内容に置き換え、それぞれのワークフ
ローシステムに合わせた相互処理にカスタマイズすることを想定しています。
XMP メタデータの使用
ユーザーは、ファイル/コンテンツファイル情報を選択して、メタデータを入力および編集できます。 この
メタデータは、InCopy ファイルに保存されます。 ソフトウェア開発者やシステムインテグレーターは、XMP
SDK を使用して、独自のメタデータを作成し保存できます。
2
はじめに
CS6
更新
CS5 に関する言及を削除または変更。
章の更新ステータス
インターフェイスに搭載されているツール、パネル、ダイアログボックスなど)と比べても、スクリプティ
ングほど時間と手間とコストを節約してくれるものはありません。
このマニュアルでは、すべての InCopy ユーザーを対象に説明を行います。 まず、スクリプトを初めて作成す
る方のために、スクリプトの基本事項について説明します。 次に、他のアプリケーション向けにスクリプト
を作成した経験がある方のために、InCopy スクリプティングの特徴について説明します。 さらに、スクリプ
トを InCopy にインストールして実行する方法や、InCopy スクリプティングで実現できることと実現できない
こと、スクリプトの作成に必要なソフトウェアについても説明します。
InCopy のユーザーインターフェイスで行える操作のほとんどは、スクリプトを使用して実行することができ
ます。 テキストの入力やフォーマット、テキストの検索や変更、注釈の追加、ドキュメントページの印刷や
書き出しなど、 ドキュメントやその内容に変更を加えるアクションは、すべてスクリプトで実行できます。 ま
た、ユーザーインターフェイスでは行えない高度な処理も実行できます。
スクリプトを使用すれば、メニューの作成、メニュー項目の追加、ダイアログボックスやパネルの作成と表
示、ユーザーインターフェイスで行われた選択への応答などが行えます。 また、テキストファイルの読み取
りや書き込み、XML データの解析、他のアプリケーションとの通信なども行えます。 スクリプトは、カーソ
ル位置でのタブストップの設定のような単純な処理から、非常に複雑な処理まで、様々な用途に活用できま
クフロー全体を自動化するスクリプトを作成できるようになります。
ワークスペースの設定やキーボードショートカットの定義など、スクリプトで実行できない操作がいくつか
ありますが、その多くはユーザーインターフェイスに関係する操作です。 また、InCopy ドキュメントに新し
い種類のオブジェクトを追加したり、InCopy の基本機能を新たに追加する(例えば、新しいテキストコンポ
ジションエンジンを追加する)こともできません。 このような拡張を行いたい場合は、InCopy ソフトウェア
開発キット(SDK)を使用して、C++ でコンパイル済みのプラグインを作成する必要があります。
InCopy は、主に Adobe InDesign® ドキュメントの製作工程の一部として使用されます。したがって、このマ
ニュアルでは、InCopy だけでなく InDesign についても触れています。 また、InDesign と InCopy のスクリプ
ティングは非常に似ています。 InDesign スクリプティングについて詳しくは、『Adobe InDesign スクリプティ
ングチュートリアル』および『Adobe InDesign スクリプティングガイド』を参照してください。
スクリプトのインストール
InCopy にスクリプトをインストールするには、InCopy アプリケーションフォルダー内の Scripts フォルダーに
ある Scripts Panel フォルダーに、スクリプトファイルを保存します。
または、ユーザー環境設定フォルダーの Scripts Panel フォルダーにスクリプトを保存します。 ユーザー環境設
定フォルダーは、次の場所にあります。
< ユーザー名 >
はユーザー名を表し、~(チルド)はシステムボリュー
ムを表します。
Mac OS®:
ユーザ /< ユーザー名 >/ ライブラリ /Preferences/Adobe
InCopy/
Version 8.0-J/ja_JP/Scripts/Scripts Panel
このフォルダーに保存したスクリプトは、InCopy のスクリプトパネルに表示されます(このパネルを表示す
るには、ウィンドウ/スクリプトを選択します)。
11
第 2 章 はじめに スクリプトの実行 12
Scripts Panel フォルダーには、スクリプトやスクリプトが保存されているフォルダーのエイリアスやショート
カットを保存することもできます。これらのエイリアスやショートカットも、スクリプトパネルに表示され
ます。
スクリプトの実行
スクリプトを実行するには、スクリプトパネルを表示し(ウィンドウ/スクリプトを選択し)、スクリプトパ
ネルに表示されているスクリプト名をダブルクリックします。 多くの場合、何らかのユーザーインターフェ
イス(ダイアログボックスやパネルなど)が表示され、必要に応じて警告が表示されます。
スクリプトパネルの使用
スクリプトパネルでは、コンパイル済みまたは未コンパイルの AppleScript(拡張子が
.spt
、
.as
、
.applescript
のファイル)
.js
または
.jsx
のファイル)
.vbs
の
ファイル)、実行可能ファイルを実行できます。
スクリプトパネルに表示されているスクリプトを編集するには、Option キー(Mac OS)または Alt キー
(Windows)を押しながらスクリプト名をダブルクリックします。 スクリプトのファイルタイプに対応するエ
ディターで、そのスクリプトファイルが開かれます。
スクリプトパネルに表示されているスクリプトの保存フォルダーを開くには、Command キー(Mac OS)ま
たは Ctrl キーと Shift キー(Windows)を押しながらスクリプト名をダブルクリックします。 または、スクリ
プトパネルのメニューから「Finder で表示」(Mac OS)または「エクスプローラーで表示」(Windows)を選
択します。 そのスクリプトが保存されているフォルダーが、Finder(Mac OS)またはエクスプローラー
(Windows)で表示されます。
スクリプトは一連のアクションとして実行されます。つまり、編集メニューから「取り消し」を選択して、
スクリプトで行った各変更を取り消すことができます。 スクリプトのトラブルシューティングを行う場合は、
これによって問題のアクションが見つけやすくなります。
スクリプトにキーボードショートカットを追加するには、編集/キーボードショートカットを選択し、セッ
トメニューから編集可能なショートカットセットを選択し、機能エリアメニューから「スクリプト」を選択
します。 スクリプトパネル内のスクリプトが一覧表示されます。 スクリプトを選択し、InCopy の通常の機能
と同じようにキーボードショートカットを割り当てます。
AppleScript 言語の詳細
AppleScript バージョン 1.6 またはそれ以降がインストールされているシステムで、AppleScript のスクリプト
エディタを使用する必要があります。 AppleScript は、すべての Mac OS® に付属しています。また、Apple 社の
しています。スクリプトエディタには、次のメニューからアクセスできます。
Mac OSX 10.5
アプリケーション/ AppleScript /スクリプトエディタ
Mac OSX 10.6
アプリケーション/ユーティリティ/ AppleScript エディタ
また、Script Debugger(Late Night Software 社の製品。 http://www.latenightsw.com
)などのサードパーティー
のスクリプトエディタを使用することもできます。
第 2 章 はじめに このマニュアルに掲載されているスクリプトの使用方法 13
このマニュアルに掲載されているスクリプトの使用方法
このマニュアルに記載されているスクリプトを使用するには、チュートリアルスクリプトファイルを開くか
(ファイル名は各スクリプトの前に記載されています)、この章に記載されているコードをコピーします。
スクリプトファイルは、
InCopyCS6ScriptingGuideScripts.zip
という Zip アーカイブに格納されています。
アーカイブを圧縮解除したら、目的のスクリプト言語(AppleScript、JavaScript または VBScript)で作成され
たスクリプトが保存されているフォルダーを、Scripts Panel フォルダーに移動します。 これらのスクリプト
ファイルを利用するほうが、スクリプトを直接入力したり、このマニュアルからスクリプトをコピーして貼
り付けるよりも簡単です。
スクリプトアーカイブを入手できない場合、この章に掲載されているスクリプトコードを入力することもで
1.
この Adobe PDF 形式のマニュアルからスクリプトをコピーして、Apple 社のスクリプトエディタに貼り
付けます。
2.
Scripts Panel フォルダーに、プレーンテキストファイルとしてスクリプトを保存します(
を参照)。ファイル拡張子は
.applescript
を使用します。
3.
ウィンドウ/スクリプトを選択して、スクリプトパネルを表示します。
4.
スクリプトパネルでスクリプト名をダブルクリックして、スクリプトを実行します。
手入力でスクリプトを作成する方法は、この章に掲載されているスクリプトに対してのみ有効です。 他の章
に掲載されているスクリプトは、断片的なスクリプトです。完全なスクリプトではありません。 他の章のス
クリプトを実行するには、スクリプトアーカイブのスクリプトを使用する必要があります。
注意 : このマニュアルからスクリプトをコピーして貼り付ける場合は、レイアウトの都合で途中で改行され
ている文があるとエラーになる点に注意してください。 このようなエラーを発見するのは難しいことが多い
ので、Zip アーカイブのスクリプトを使用することをお勧めします。
最初の InCopy スクリプトの作成
では、InCopy スクリプトを実際に作成してみましょう。ここでは、新規ドキュメントを作成し、テキストフ
レームを追加し、そのテキストフレームにテキストを入力するスクリプトを作成します。 非常に簡単な作業
のように思えますが、このスクリプトでは次の処理を行います。
InCopy との通信を確立する。
新規ドキュメントを作成する。
ストーリーにテキストを追加する。
スクリプトエディタアプリケーションを起動します(AppleScript フォルダーの中の Applications フォルダー
にあります)。 次のスクリプトを入力します(または、
HelloWorld.applescript
というチュートリアルスクリ
プトを開きます)。 tell application "Adobe InCopy CS6" set myDocument to make document set myStory to story 1 of myDocument tell myStory set contents to "Hello World!" end tell end tell
Scripts Panel フォルダーに、テキストファイルとしてスクリプトを保存します(
.applescript
スクリプトを実行するには、スク
リプトパネルでスクリプト名をダブルクリックします。または、スクリプトエディタウィンドウで「実行」
をクリックします。
第 2 章 はじめに スクリプティング用語と InCopy オブジェクトモデル 14
スクリプトの動作の説明
ここでは、Hello World スクリプトの動作について、順を追って説明します。
1.
InCopy アプリケーションオブジェクトとの通信を確立します。 tell application "Adobe InCopy CS6"
2.
新規ドキュメントを作成して、その参照を取得します。
Set myDocument to make document
3.
ドキュメントの最初のストーリーへの参照を取得します(独立したドキュメントには必ずストーリーが
含まれています)。 set myStory to story 1 of myDocument tell myStory
4.
コンテンツのプロパティに文字列を設定して、ストーリーにテキストを追加します。 set contents of myStory to "Hello World!"
スクリプティング用語と InCopy オブジェクトモデル
ここでは、次のスクリプトに進む前に、スクリプト言語に関する一般的な用語と、InCopy スクリプティング
に固有の用語について説明します。
スクリプティングの用語
まず、スクリプティングに関する一般的な用語や概念について説明します。
コメント
コメントを使用して、スクリプトに説明用のテキストを追加することができます。 コメントはスクリプトの
実行時には無視され、エラーが発生しないようになっています。 スクリプトの処理について、自分や他人の
ために注釈を残しておきたい場合は、コメントを使用すると便利です。 このマニュアルのチュートリアルス
クリプトでも、コメントを使用しています。
AppleScript でコメントを入力するには、コメントの左に「
--
」と入力します。または、「
(*
」と「
*)
」でコ
メントを囲みます。 次に例を示します。
--this is a comment
(* and so is this *)
値
InCopy スクリプティングで使用される値の例としては、テキストの文字のポイントサイズ、注釈の内容、ド
キュメントのファイル名などがあります。 値とは、スクリプトで処理を行う際に使用するデータのことです。
値にどのような種類のデータが含まれるかは、値の型によって定義されます。 例えば、単語が格納されてい
る値の型は文字列で、段落の行送りの値の型は数値です。 通常、スクリプトで使用される値は数値かテキス
トです。 InCopy スクリプティングで最もよく使用される値の型を、次の表に示します。
第 2 章 はじめに スクリプティング用語と InCopy オブジェクトモデル 15
値の型
Boolean
Integer fixed または real
String
List
説明
真(True)か偽(False)かを表す論
理値。
例
True
14
数と負の整数があります。
精度の高い数値。小数点が含まれる
ことがあります。
一連のテキスト文字。 文字列は引用
符で囲みます。
値のリスト(この値はどの型であっ
てもかまいません)。
13.9972
" これは文字列です "
{"0p0", "0p0", "16p4", "20p6"}
値の型の変換
ら文字列への変換(テキストの中に挿入したり、ダイアログボックスに表示したりする場合に行います)と、
文字列から数値への変換(ポイントサイズやページ位置を設定する場合に行います)の 2 つです。
--To convert from a number to a string: set myNumber to 2 set myString to (myNumber as string)
--To convert from a string to a number: set myString to "2" set myNumber to (myString as integer)
--if your string contains a decimal value, use "as real" rather than "as integer"
変数
変数は、値を格納する入れ物のようなものです。 「変数」という名前が表しているように、この入れ物に格
納する値は変更することができます。 変数には数値が格納されることもありますし、テキスト文字列や、
照するときにはこの名前を使用します。 変数に値を格納するには、その変数にデータを割り当てます。
InCopy のすべてのサンプルスクリプトやチュートリアルスクリプトでは、変数名はすべて my
で始まってい
ます。 このようにすることで、スクリプトで独自に作成した変数と、スクリプト言語の予約語を簡単に区別
できるようにしています。
変数への値の割り当て
変数に値や文字列を割り当てるのは簡単です。その方法を次の例に示します。 set myNumber to 10 set myString to "Hello, World!" set myTextFrame to make text frame at page 1 of myDocument
変数には、意味のある名前を付けるようにしてください。 firstPage
や corporateLogo
などは良い例です。 x
や c
などは悪い例です。
スクリプトの実行速度に悪影響を与えることはありません。
変数は、1 つの単語である必要があります。ただし、読みやすくするために途中で大文字を使用したり
( myFirstPage
、アンダースコアを使用したり( my_first_page
初の文字に数字を使用することはできません。また、変数名に句読点や引用符を含めることもできません。
第 2 章 はじめに
配列変数
スクリプティング用語と InCopy オブジェクトモデル 16 set myArray to {1, 2, 3, 4}
配列に含まれている要素を参照するには、その要素のインデックスを参照します。AppleScript では、配列の
最初の要素は要素 1 です。 set myFirstArrayItem to item 1 of myArray
次の例のように、配列の中にさらに別の配列を含めることができます。 set myArray to {{0, 0}, {72, 72}}
変数の値の型を調べる
オブジェクトの値の型に基づいて判断を行いたい場合があります。 例えば、選択されたテキストに対して処
理を実行するスクリプトでは、何も選択されていない場合には処理を停止する必要があります。
-- Given a variable of unknown type, "myMysteryVariable"...
set myType to class of myMysteryVariable
--myType will be an AppleScript type (e.g., rectangle)
演算子
演算子は、変数や値を使用して計算(加算、減算、乗算、除算)を実行し、値を返します。 例えば、
MyWidth/2
では、変数 myWidth
に格納されている値の半分の値が返されます。
また、演算子を使用して比較(等しい(
=
こともできます。 例えば、
、等しくない(
<>
)、より大きい(
>
、より小さい(
<
))を行う
MyWidth > myHeight
では、 myWidth
が myHeight
よりも大きい場合には true
(または 1)が、そうでない場合には false
(0)が返
されます。
AppleScript では、アンパサンド(
&
)を使用して 2 つの文字列を連結(結合)させることができます。 例え
ば、
"Pride " & "and Prejudice"
とすると、次の文字列が返されます。
"Pride and Prejudice"
条件文
「もし選択されているテキストのサイズが 12 ポイントなら、そのポイントサイズを 10 ポイントに設定しなさ
(選択されているテキストのカラー、ドキュメントのページ数、日付など)を評価して、その結果に従って処
理を行うことができます。 条件文は、ほとんどの場合 if
で始まります。
第 2 章 はじめに
制御構造
スクリプティング用語と InCopy オブジェクトモデル 17
令をしていたことでしょう。 スクリプティングの用語では、このような命令のことを制御構造と呼びます。 制
御構造を使用すると、反復作業、つまりループ処理を行うことができます。 ループの考えは、それぞれルー
プ内で変化があったかなかったかに関わらず、特定の条件を満たすまで、ある動作を何度も何度も繰り返す
ことです。 repeat
で始まります。
ハンドラー
ハンドラーとは、スクリプトの中から参照することができるスクリプティングモジュールのことです。 ハン
ドラーに値(または一連の値)を渡して、返される値を取得する、というのが一般的な使い方です。 ハンド
ラーは、何か特別なコードで構成されているわけではありません。これらは、スクリプトの中で同じコード
を何度も入力する手間を省くためのものです。 ハンドラーは on
で始まります。
InDesign および InCopy オブジェクトモデルの理解
InCopy と InDesign ドキュメントの関係を考えるとき、おそらくプログラムと、そのコンポーネントの関係を
考えるでしょう。 同様に、段落はテキストフレームの中にあり、テキストフレームはページの中にあり、 ペー
ジはスプレッドの中にあり、いくつかのスプレッドが集まって 1 つのドキュメントを構成していることもご
存知だと思います。 ドキュメントにはカラー、スタイル、レイヤー、マスタースプレッドなども含まれてい
ます。 ドキュメントにオブジェクトを作成するユーザーは、それらの間に一定の序列があることを直感的に
理解しています。
InDesign や InCopy も、ドキュメントのコンテンツを同じような考え方で「認識」しています。ドキュメント
の中にはページが含まれており、ページの中にはページアイテム(テキストフレーム、長方形、楕円形など)
が含まれています。 テキストフレームの中には文字、単語、段落、アンカーフレームなどが含まれています。
グラフィックフレームの中には画像、EPS、PDF などが含まれています。グループの中には他のページアイテ
ムが含まれています。 これらはすべて、InDesign パブリケーションを構成するオブジェクトです。InDesign お
よび InCopy スクリプトでは、このオブジェクトに対して何らかの操作を行います。
パブリケーションの中にあるオブジェクトは、一定の序列に従って編成されています。 例えば、段落はス
トーリーの中にあり、ストーリーはドキュメントの中にあり、ドキュメントは InCopy アプリケーションオブ
ジェクトの中にあります。 オブジェクトモデルや階層という言葉は、このような構造のことを指しています。
目的のオブジェクトにアクセスするためには、このオブジェクトモデルを理解している必要があります。
InCopy の構造を理解することが、InCopy スクリプティングをマスターする秘訣であると言えます。
オブジェクトにはプロパティ(属性)があります。 例えば、テキストオブジェクトには、テキストの書式設
定に使用するフォント、ポイントサイズ、テキストに適用する行送りなどのプロパティがあります。
プロパティには値が設定されます。例えば、テキストのポイントサイズには、ポイント数を表す数値や、自
動行送りを表す「Auto」などの文字列が設定されます。 また、テキストの塗りカラーには、1 つのカラー、グ
ラデーション、混合インキ、スウォッチなどが設定されます。
プロパティには、読み書き可能なものと読み取り専用のものがあります。 読み書き可能なプロパティは、別
の値に変更することができますが、読み取り専用のプロパティは変更できません。
また、オブジェクトにはメソッドが用意されています。 これは、そのオブジェクトが実行できるアクション
を表しており、スクリプトの中で「動詞」として使用されます。 例えば、ドキュメントオブジェクトには、
印刷、書き出し、保存などを行うメソッドが用意されています。
メソッドはパラメーターを取ります。パラメーターは、メソッドの動作を定義するための値です。 例えば、 open メソッドは、開くファイルを定義するためのパラメーターを取ります。
解するための概念的なフレームワークなので、InCopy スクリプティングで利用できるオブジェクトを完全に
網羅したものではありません。
第 2 章 はじめに スクリプティング用語と InCopy オブジェクトモデル 18 application documents libraries books application preferences application defaults application events application menus application properties application methods a document document preferences document defaults document events document properties document methods document elements pages or spreads stories page text objects
この図に示されている各オブジェクトについて、次の表で説明します。 page items
用語
Application
Application defaults
Application events
Application menus
Application methods
Application preferences
Application properties
Books
Document
表しているもの
InCopy。
アプリケーションのデフォルト設定。カラー、段落スタイル、オブジェクトスタイルな
ど。 アプリケーションのデフォルト設定はすべての新規ドキュメントに影響を与えます。
ユーザーやスクリプトがアプリケーションを操作したときに発生します。 例えば、ドキュ
メントのオープン、クローズ、保存を行ったときや、メニュー項目を選択したときなどに
イベントが生成されます。 イベントに反応してスクリプトを実行させることができます。
InCopy のユーザーインターフェイスに表示されるメニュー、サブメニュー、コンテキスト
メニュー。 メニューの選択にスクリプトを関連付けたり、スクリプトからメニューアク
ションを実行したりできます。
アプリケーションが実行できるアクション。テキストの検索と変更、選択項目のコピー、
新規ドキュメントの作成、ライブラリのオープンなど。
テキストの環境設定、PDF 書き出しの環境設定、ドキュメントの環境設定など。 環境設定
オブジェクトの多くはドキュメントレベルにも存在しています。 ユーザーインターフェイ
スの場合と同じように、アプリケーションの環境設定は新規ドキュメントに適用されま
す。ドキュメントの環境設定は特定のドキュメントの設定を変更します。
アプリケーションのプロパティ。アプリケーションのフルパス、アプリケーションのロ
ケール、ユーザー名など。
開かれているブックのコレクション。
InCopy ドキュメント。
第 2 章 はじめに スクリプティング用語と InCopy オブジェクトモデル 19
用語
Document defaults
Document elements
Document events
Document methods
Document preferences
Document properties
Documents
Libraries
Page
Page item
表しているもの
ドキュメントのデフォルト設定。デフォルトのカラー、段落スタイル、デフォルトのテキ
スト書式など。
ドキュメントのストーリー、読み込んだグラフィック、ページなど。 ページやストーリー
もドキュメント要素ですが、これらは他のオブジェクトを格納するコンテナとして特に重
要な要素なので、この表の前にある図では独立して示されています。ドキュメント要素に
は、このほかにも、長方形、楕円形、グループ、XML 要素などの、読み込んだり作成した
りできるあらゆる種類のオブジェクトが含まれます。
ドキュメントレベルで発生するイベント。テキストの読み込みなど。 この表の
「Application events」を参照してください。
ドキュメントが実行できるアクション。ドキュメントのクローズ、印刷、書き出しなど。
ドキュメントの環境設定。ガイド、表示、ドキュメントの環境設定など。
ドキュメントのファイル名、ページ数、原点の位置など。
開かれているドキュメントのコレクション。
開かれているライブラリのコレクション。
InCopy ドキュメント内の 1 つのページ。
ページ上に作成または配置できる任意のオブジェクト。 ページアイテムには、テキストフ
レーム、長方形、グラフィックの線、グループなど多くの種類があります。
InCopy ドキュメント内のページまたはスプレッド。
Pages or spreads
Stories
Text objects
InCopy ドキュメント内のテキスト。
InCopy ストーリーには、文字、単語、線、段落、テキスト列などのテキストオブジェクト
が含まれます。
InCopy オブジェクトモデルの参照
クトとそのプロパティやメソッドに関する参照情報は、すべてモデルに格納されており、スクリプト編集ア
プリケーションで参照することができます。
InCopy の AppleScript 用語説明を参照するには:
1.
InCopy を起動します。
2.
スクリプトエディタを起動します。
3.
スクリプトエディタで、ファイル/用語説明を開くを選択します。 スクリプト可能なアプリケーション
のリストが表示されます。
第 2 章 はじめに スクリプティング用語と InCopy オブジェクトモデル 20
4.
InCopy アプリケーションがこの中にある場合はそれを選び「OK」をクリックします。この中にない場合
は、ここでブラウズボタンをクリックすると、標準のオープンダイアログボックスが表示されるので、
クトのコレクション)のリストが表示されます。
5.
スイートを選択すると、そのスイートに含まれるオブジェクトとメソッド(コマンド)が表示されます。
オブジェクトを選択すると、そのオブジェクトのプロパティが表示されます。
第 2 章 はじめに スクリプティング用語と InCopy オブジェクトモデル 21
測定値と位置
InCopy では、どのアイテムやオブジェクトも、設定されている測定値に従ってページ上に配置されます。
InCopy の座標系の仕組みと、使用される測定単位について理解しておくと、スクリプトを書く際にその知識
が役に立ちます。
座標
他のページレイアウトプログラムやドロープログラムと同じように、InCopy でも、単純な 2 次元座標を使用
してページやスプレッド上のオブジェクトの位置を設定します。 座標は 2 つの値の組で表しますが、そのう
ちの水平成分を
x と呼び、垂直成分を y と呼びます。 選択ツールでオブジェクトを選択すると、変形パネルや
コントロールパネルにこの座標が表示されます。 座標は、InCopy のユーザーインターフェイスと同様に、定
規の現在の原点からの相対位置で測定されます。
は、InCopy の座標では、垂直軸(
y 軸)の原点より下が正の数であり、原点より上が負の数である、という
ことです。
測定単位
とができます。 数値を渡したときには、パブリケーションの現在の測定単位が使用されます。測定文字列
(後述の表を参照)を渡したときには、その文字列で指定した測定単位が使用されます。
れる測定値は、変形パネルに表示される測定値と表記の仕方が違うことがあります。 例えば、現在の測定単
位系がパイカである場合、端数のある値はパイカとポイントの形(変形パネルでの表記法)ではなく、小数
の形で返されます。 例えば、「1p6」は「1.5」と返されます。 このようにしている理由は、スクリプティング
システムで測定文字列を使用して算術演算を行おうとすると問題が生じるからです。 例えば、「13p4」に
「0p3.5」を足そうとするとスクリプトエラーが発生します。13.333 に .2916(どちらもパイカに換算した値)
を足す場合にはエラーは発生しません。
スクリプトで特定の測定値の加減乗除を行う場合には、スクリプトの始めの部分で測定単位を設定します。
そして、スクリプトの終わりの部分で、スクリプトを実行する前の測定単位に戻します。 または、多くのサ
ンプルスクリプトで行っているように、測定単位をオーバーライドすることができます。 これを行うには、
特別な文字が含まれた文字列を使用します。次に例を示します。
オーバーライド c cm i(または in) mm p pt
意味
シセロ(必要に応じて c の後にディド値を追加できます)
センチメートル
インチ
ミリメートル
パイカ(必要に応じて p の後にポイント値を追加できます)
ポイント
例
1.4 c
.635 cm
.25 i
6.35 mm
1p6
18 pt
第 2 章 はじめに 「Hello World」への機能の追加 22
「Hello World」への機能の追加
次に、最初のスクリプトで作成した「Hello World」パブリケーションに変更を加える新しいスクリプトを作
アクティブなドキュメントを取得する。
最初のストーリー内のテキストのフォーマットを変更する。
注釈を追加する。
ImprovedHelloWorld チュートリアルスクリプトを開くか、または次の手順に従ってスクリプトを作成します。
1.
作成したドキュメントが開いていることを確認します。 ドキュメントを保存せずに閉じてしまった場合
は、
HelloWorld.applescript
スクリプトをもう一度実行すればドキュメントが新たに作成されます。
2.
スクリプトエディタでファイル/新規スクリプトを選択して、新しいスクリプトを作成します。
3.
次のコードを入力します。 tell application "Adobe InCopy CS6"
--Get a reference to a font.
try
--Enter the name of a font on your system, if necessary.
set myFont to font "Arial" end try
--Get the active document and assign the result to the variable "myDocument" set myDocument to document 1 tell story 1 of myDocument
--Change the font, size, and paragraph alignment.
try set applied font to myFont end try set point size to 72 set justification to center align
--Enter the note at the last insertion point of the story.
tell insertion point -1 set myNote to make note set contents of text 1 of myNote to "This is a note." end tell end tell end tell
4.
スクリプトを保存します。
スクリプトパネルでスクリプト名をダブルクリックして、新しいスクリプトを実行します。
3
スクリプティング機能
CS6 編集
章の更新ステータス
および 3 つの副節を、更新、修正および明確化しました。
この章では、InCopy のスクリプティング環境に関連するスクリプティングテクニックを紹介します。 InCopy
のスクリプトモデルを構成するオブジェクトのほとんどは、アプリケーションのデフォルトやドキュメント
を操作するためのオブジェクトですが、 この章ではまず、スクリプトそのものを制御する方法について説明
します。
この章の内容は、次のとおりです。
script preferences
オブジェクトとそのプロパティ
実行中のスクリプトへの参照の取得
以前のバージョンのスクリプトオブジェクトモデルに基づいたスクリプトの実行
do script
メソッドを使用したスクリプトの実行
InCopy の起動時におけるスクリプトの自動実行
ここでは、読者が
を既に読んでおり、該当するスクリプト言語で InCopy のスクリプトを
作成、インストール、実行する方法を理解しているものとして説明を行います。
スクリプトの環境設定
script preferences
オブジェクトには、InCopy でのスクリプトの実行方法に関連するオブジェクトやプロパ
ティが用意されています。 次の表に、script preferences オブジェクトの各プロパティの詳細を示します。
プロパティ enable redraw scripts folder scripts list
説明
スクリプトパネルからスクリプトを実行している最中の画面の再描画をオン
またはオフにします。
Scripts フォルダーへのパス。
使用可能なスクリプトのリスト。 このプロパティは、次に示すような配列の
配列を返します。
[[
fileName, filePath], ]
fileName
はスクリプトファイルの名前を表し、
filePath
はスクリプトへの
フルパスを表します。 この機能を使用すれば、目的のスクリプトがインス
トールされているどうかを確認できます。
23
第 3 章 スクリプティング機能 現在のスクリプトの取得 24
プロパティ user interaction level version
説明
このプロパティは、ユーザーに表示する警告やダイアログボックスを制御し
ます。 このプロパティを never interact
に設定すると、警告やダイアログ
ボックスは一切表示されなくなります。 interact with alerts
に設定すると、
警告は有効になりますが、ダイアログボックスは無効になります。 interact with all
に設定すると、警告とダイアログボックスは通常どおりに表示され
合に便利です。InCopy では、フォントやリンク先のグラフィックファイル
が見つからないと警告が表示されます。 このプロパティを never interact
に
設定してからドキュメントを開き、スクリプトを終了する直前にプロパティ
を元に戻せば( interact with all
、警告が表示されるのを避
けられます。
を参照してください。 このプロパティは、アプリ
ケーションのバージョンと同じではないことに注意してください。
現在のスクリプトの取得
現在のスクリプトへの参照を取得するには、アプリケーションオブジェクトの active script
プロパティを
使用します。 このプロパティは、現在のスクリプトが保存されている場所を基準にしてファイルやフォル
ダーを検索する場合に役立ちます。次のスクリプトにその例を示します(チュートリアルスクリプトの tell application "Adobe InCopy CS6" set myScript to active script display dialog ("The current script is: " & myScript) tell application "Finder" set myFile to file myScript set myParentFolder to container of myFile end tell display dialog ("The folder containing the active script is: " & myParentFolder) end tell
スクリプトエディタでスクリプトをデバッグしている場合は、 active script
プロパティを取得しようとする
とエラーが発生します。 active script
プロパティで返されるのは、スクリプトパレットから実行したスクリ
プトのみです。
スクリプトのバージョン対応
InCopy では、以前のバージョンの InCopy スクリプトオブジェクトモデルに基づいて作成されたスクリプトを
実行できます。 新しいバージョンの InCopy で古いスクリプトを実行する場合は、次の点に注意する必要があ
ります。
ターゲットの設定 - スクリプトを実行する InCopy のバージョン(現在のバージョン)をターゲットに設
言語によって異なります。
コンパイル - この段階では、スクリプトで使用されている名前が InCopy で認識できるスクリプト ID に
異なります。
インタープリターによる実行 - この段階では、スクリプト ID が InCopy の適切なハンドラーに関連付けら
れます。これにより InCopy は、以前のバージョンのスクリプトオブジェクトモデルに基づいて作成され
たスクリプトも正しく解釈できるようになります。 そのためには、スクリプトでアプリケーションのス
第 3 章 スクリプティング機能 スクリプトのバージョン対応 25
クリプト環境設定に古いオブジェクトモデルを明示的に設定するか(
に示すとおり)
フォルダー
Version 8.0 Scripts
Version 7.0 Scripts
Version 6.0 Scripts
Version 5.0 Scripts
Version 2.0 Scripts
スクリプトの InCopy バージョン
CS6
CS5 および CS5.5
CS4
CS3
CS2
ターゲットの設定
スクリプトを実行する InCopy のバージョン(現在のバージョン)が、スクリプトでターゲットとして明示的
または暗黙的に設定されている必要があります。 スクリプトパネルからスクリプトを実行すると暗黙的に
ターゲットが設定されます。
AppleScript で明示的にターゲットを設定するには、 tell
文を使用します。
--Target InCopy CS6 tell application "Adobe InCopy CS6"
コンパイル
通常は、ターゲットとして設定したバージョンの用語説明を使用してコンパイルが実行されますが、 using terms from
文を使用すれば、別のバージョンの InCopy の用語説明を使用してコンパイルを実行できます。
えば、CS6(バージョン 8.0)内で CS5 スクリプト(バージョン 7.0)を使用するには、次のようにします。 tell application "Adobe InCopy CS6" --target CS6 using terms from application "InCopy CS5" --compile using CS5
--InCopy CS5 version script goes here.
end using terms from end tell
これを動作させるには、application オブジェクトの publish terminology
コマンドを使用して、以前のバー
ジョンの AppleScript 用語説明を生成する必要があります。 これによって、InCopy の環境設定フォルダー内の
Scripting Support
フォルダーにある、DOM のバージョンと同じ名前のフォルダーに用語説明が生成されま
す。
/ ユーザ /< ユーザー名 >/ ライブラリ /Preferences/Adobe InCopy/Version
8.0-J/ja_JP/Scripting Support/8.0
フォルダーに生成するには、次のようにします。 tell application "Adobe InCopy CS6"
--publish the InCopy CS5 dictionary (version 8.0 DOM)
publish terminology version 8.0
end tell
インタープリターによる実行
インタープリターで使用するスクリプトオブジェクトモデルのバージョンを取得したり設定したりするには、
InCopy アプリケーションオブジェクトの script preferences
オブジェクトを使用します。
アプリケーションの現在のバージョンに設定されており、変更されるまでそのバージョンが使用されます。
例えば、スクリプトオブジェクトモデルのバージョンを CS5 に変更するには、次のようにします。
--Set to 7.0 scripting object model set version of script preferences to 7.0
第 3 章 スクリプティング機能 do script メソッドの使用 26
do script メソッドの使用
do script
メソッドを使用すると、スクリプトの中で別のスクリプトを実行することができます。
ドには、有効なスクリプトコードを表す文字列か、ディスク上のスクリプトファイルを指定できます。 指定
するスクリプトは、現在のスクリプトと同じ言語であっても、異なる言語であってもかまいません。 使用で
きる言語はプラットフォームによって異なります。Mac OS® の場合は AppleScript または JavaScript を実行で
きます。Windows® の場合は VBScript または JavaScript を実行できます。 do script
メソッドは、次の様々な場合に利用できます。
使用したい機能が、メインのスクリプト言語ではサポートされておらず、別の言語でサポートされてい
る場合。 例えば、VBScript にはファイルブラウザーやフォルダーブラウザーを表示する機能はありません
が、JavaScript にはこの機能が用意されています。 AppleScript では三角関数(サインやコサイン)の計算
に時間がかかる場合がありますが、JavaScript では高速に処理できます。 JavaScript では、Microsoft® Excel
スプレッドシートのセルの内容を照会することはできませんが、AppleScript や VBScript を使用すれば行
うことができます。 どの場合も、別の言語で断片的なスクリプトコードを作成して do script
メソッドで
実行すれば、メインのスクリプト言語の制約を回避することができます。
スクリプトを動的に生成して実行する場合。 実行時にスクリプトの文字列を動的に生成して、 do script
メソッドで実行することができます。 この方法は、選択されている内容や作成するオブジェクトの属性
に基づいてダイアログボックスやパネルをカスタマイズしたい場合などに適しています。
オブジェクトにスクリプトを埋め込む場合。 do script
メソッドを使用すれば、オブジェクトの label
プ
ロパティに文字列として保存されているスクリプトを実行することができます。 このテクニックを利用
すると、特定のパラメーターに基づいてレイアウトプロパティを制御したり内容を更新したりするスク
リプトを、オブジェクト自体に埋め込むことができます。 また、XML 要素にも、属性またはコンテンツ
を
参照してください。
do script へのパラメーターの渡し方
do script
で実行するスクリプトにパラメーターを渡すには、次のようにします(チュートリアルスクリプト
の DoScriptParameters より)。 tell application "Adobe InCopy CS6"
--Create a list of parameters.
set myParameters to {"Hello from do script", "Your message here."}
--Create a JavaScript as a string.
set myJavaScript to "alert(¥"First argument: ¥" + arguments[0] + ¥"¥¥rSecond argument: ¥" + arguments[1])"
--Run the JavaScript using the do script command.
do script myJavaScript language javascript with arguments myParameters
--Create an AppleScript as a string.
set myAppleScript to "tell application ¥"Adobe InCopy CS6¥"" & return set myAppleScript to myAppleScript & "display dialog (¥"First argument: ¥" & item 1 of arguments & return & ¥"Second argument: ¥" & item 2 of arguments)" & return set myAppleScript to myAppleScript & "end tell"
--Run the AppleScript using the do script command.
do script myAppleScript language applescript language with arguments myParameters end tell
do script からの戻り値
do script
で実行するスクリプトから値を返すには、アプリケーションの script args
オブジェクトを使用し
ます(この名前は、「script arguments」を縮めたものです)。 次のスクリプトにその例を示します(完全なス
クリプトについては、DoScriptReturnValue というチュートリアルスクリプトを参照してください)。
第 3 章 スクリプティング機能 起動時におけるスクリプトの自動実行 27 tell application "Adobe InCopy CS6"
--Create a string to be run as an AppleScript.
set myAppleScript to "tell application ¥"Adobe InCopy CS6¥"" & return set myAppleScript to myAppleScript & "tell script args" & return set myAppleScript to myAppleScript & "set value name ¥"ScriptArgumentA¥" value ¥"This is the first AppleScript script argument value.¥"" & return set myAppleScript to myAppleScript & "set value name ¥"ScriptArgumentB¥" value ¥"This is the second AppleScript script argument value.¥"" & return set myAppleScript to myAppleScript & "end tell" & return set myAppleScript to myAppleScript & "end tell"
--Run the AppleScript string.
do script myAppleScript language applescript language
--Retrieve the script argument values set by the script.
tell script args set myScriptArgumentA to get value name "ScriptArgumentA" set myScriptArgumentB to get value name "ScriptArgumentB" end tell
--Display the script argument values in a dialog box.
display dialog "ScriptArgumentA: " & myScriptArgumentA & return & "ScriptArgumentB: " & myScriptArgumentB
--Create a string to be run as a JavaScript.
set myJavaScript to "app.scriptArgs.setValue(¥"ScriptArgumentA¥", ¥"This is the first
JavaScript script argument value.¥");" & return set myJavaScript to myJavaScript & "app.scriptArgs.setValue(¥"ScriptArgumentB¥", ¥"This is the second JavaScript script argument value.¥");" & return
--Run the JavaScript string.
do script myJavaScript language javascript
--Retrieve the script argument values set by the script.
tell script args set myScriptArgumentA to get value name "ScriptArgumentA" set myScriptArgumentB to get value name "ScriptArgumentB" end tell
--Display the script argument values in a dialog box.
display dialog "ScriptArgumentA: " & myScriptArgumentA & return & "ScriptArgumentB: " & myScriptArgumentB end tell
起動時におけるスクリプトの自動実行
InCopy の起動時にスクリプトを自動実行させるには、Scripts フォルダーの下にあるスタートアップ用のフォ
ルダーである Startup Scripts フォルダーにスクリプトファイルを保存します(詳しくは、
4
テキストと組版
章の更新ステータス
CS6
変更なし
テキストの入力、編集、フォーマットといった作業は、InCopy ドキュメントの製作工程の中でも、最も時間
のかかる作業の 1 つです。 したがって、テキストや書式に関する作業を自動化できれば、生産性の大幅な向
上が期待できます。
このチュートリアルでは、テキストや書式に関する一般的な操作をスクリプトで実行する方法について説明
ここでは、読者が
を既に読んでおり、スクリプトを作成、インストール、実行する方法
を理解しているものとして説明を行います。 また、InCopy でテキストを操作する方法や、組版に関する基本
的な用語を理解しているものとしています。
テキストの入力と読み込み
ここでは、InCopy ドキュメントにテキストを配置する方法について説明します。 InCopy のユーザーインター
フェイスを使用してテキストフレームにテキストを入力したり、テキストファイルを配置したりするのと同
じように、スクリプトを使用してテキストフレームを作成し、ストーリーにテキストを挿入し、テキスト
ファイルを配置することができます。
ストーリーとテキストフレーム
InCopy レイアウトの中にあるテキストは、すべてストーリーの中に含まれています。どのストーリーにも 1
つ以上のテキストフレームを含めることができます。 独立した InCopy ドキュメントには 1 つのストーリーが
含まれています。テキストフレームは、ストーリーのテキストを表示する必要がある場合にのみ追加されま
す。
.icml
ファイル)として InDesign から書き出されたストーリーにも当ては
まります。
InDesign ドキュメントから生成された InCopy ドキュメントには、複数のストーリーが含まれていることがあ
ります。また、InDesign レイアウトで作成されたテキストフレームが必ず含まれています。 InCopy では、
InDesign と異なり、スクリプトを使用して新しいテキストフレームを追加することはできません。
InCopy ドキュメントの中にあるテキストオブジェクトの関係について詳しくは、 37 ページの「テキストオブ
を参照してください。
ストーリーへのテキストの追加
ストーリーにテキストを追加するには、 contents
プロパティを使用します。
この方法を使用して、ストーリーの末尾にテキストを追加しています(完全なスクリプトについては、
28
第 4 章 テキストと組版 テキストの入力と読み込み 29
--Adds text to the default story.
tell application "Adobe InCopy CS6" set myDocument to make document tell story 1 of myDocument set contents to "This is the first paragraph of example text."
--To add more text to the story, we'll use the last insertion point
--in the story. ("return" is a return character in AppleScript.) set the contents of insertion point -1 to return & "This is the second paragraph." end tell end tell
テキストの置換
次のスクリプトでは、適当なオブジェクトの内容を変更することで、1 つの単語をある語句に置換していま
す(完全なスクリプトについては、ReplaceWord を参照してください)。
--Enters text in the default story and then replaces
--a word in the story with a different phrase.
tell application "Adobe InCopy CS6" set myDocument to make document tell story 1 of myDocument set contents to "This is some example text."
--To add more text to the story, we'll use the last insertion point
--in the story. ("return" is a return character in AppleScript.) set the contents of word 3 to "a little bit of" end tell end tell
次のスクリプトでは、段落内のテキストを置換しています(完全なスクリプトについては、ReplaceText を参
照してください)。
--Enters text in the default story and then replaces
--the text in the second paragraph.
tell application "Adobe InCopy CS6" set myDocument to make document tell story 1 of myDocument set contents to "Paragraph 1." & return & "Paragraph 2." & return &
"Paragraph 3." & return
--Replace the text in the second paragraph without replacing
--the return character at the end of the paragraph.
set myText to object reference of text from character 1 to character -2 of paragraph 2 set contents of myText to "This text replaces the text in paragraph 2." end tell end tell
このスクリプトでは、段落 2 の改行文字を除外しています。改行を削除してしまうと、段落に適用されてい
る段落スタイルが変更される可能性があるからです。 したがって、パラメーターとして 2 つの文字を指定し
て、段落の先頭の文字から、段落の末尾の文字(改行文字)の直前にある文字までを置換しています。
特殊文字の挿入
スクリプトエディタでは Unicode がサポートされているので、InCopy に渡すテキスト文字列に Unicode 文字
を簡単に入力できます。 また、Unicode 文字の字形の識別番号を指定する
<nnnn> という InCopy ショートカッ
ト(
nnnn は、目的の文字の Unicode コード)を使用することもできます。 次のスクリプトでは、特殊文字を
いくつかの方法で入力しています(完全なスクリプトについては、SpecialCharacters を参照してください)。
第 4 章 テキストと組版 テキストの配置とテキスト読み込み環境設定の指定 30
--Shows how to enter special characters in text.
tell application "Adobe InCopy CS6" set myDocument to make document set myStory to story 1 of myDocument
--Entering special characters directly: set contents of myStory to "Registered trademark: ®" & return & "Copyright: ©" & return &
"Trademark: ™" & return
--Entering special characters by their Unicode glyph ID value: set contents of insertion point -1 of myStory to "Not equal to: <2260>" & return set contents of insertion point -1 of myStory to "Square root: <221A>" & return set contents of insertion point -1 of myStory to "Square root: <00B6>" & return
--Entering InCopy special characters by their enumerations: set contents of insertion point -1 of myStory to "Automatic page number marker: " set contents of insertion point -1 of myStory to auto page number set contents of insertion point -1 of myStory to return & "Section symbol: " set contents of insertion point -1 of myStory to section symbol set contents of insertion point -1 of myStory to return & "En dash: " set contents of insertion point -1 of myStory to En dash set contents of insertion point -1 of myStory to return end tell
特定の文字の Unicode ID を調べたい場合は、InCopy の字形パレットを使用するのが最も簡単です(このパ
レットを表示するには、書式/字形を選択します)。パレット内で文字の上にカーソルを移動すると、その文
字の Unicode 値が表示されます。 Unicode について詳しくは、 http://www.unicode.org
を参照してください。
テキストの配置とテキスト読み込み環境設定の指定
テキスト文字列の入力だけでなく、ワードプロセッサーやテキストエディターで作成したテキストファイル
を配置することもできます。 新規ドキュメントのデフォルトストーリーにテキストファイルを配置する方法
を、次のスクリプトに示します(完全なスクリプトについては、PlaceTextFile を参照してください)。 tell application "Adobe InCopy CS6" set myDocument to make document tell insertion point -1 of story 1 place "yukino:test.txt" end tell end tell
配置するテキストファイルの種類に応じた読み込みオプションを指定するには、対応する読み込み環境設定
オブジェクトを使用します。 テキスト読み込み環境設定の指定方法を、次のスクリプトに示します(完全な
スクリプトについては、TextImportPreferences を参照してください)。 スクリプトのコメントに、各プロパ
ティに指定可能な値を示します。 tell application "Adobe InCopy CS6" tell text import preferences
--Options for character set:
--ansi
--chineseBig5
--gb18030
--gb2312
--ksc5601
--macintoshCE
--macintoshCyrillic
--macintoshGreek
--macintoshTurkish
--recommendShiftJIS83pv
--shiftJIS90ms
--shiftJIS90pv
第 4 章 テキストと組版 テキストの配置とテキスト読み込み環境設定の指定 31
--UTF8
--UTF16
--windowsBaltic
--windowsCE
--windowsCyrillic
--windowsEE
--windowsGreek
--windowsTurkish set character set to UTF16 set convert spaces into tabs to true set spaces into tabs count to 3
--The dictionary property can take any of the following
--language names (as strings):
--Bulgarian
--Catalan
--Croatian
--Czech
--Danish
--Dutch
--English: Canadian
--English: UK
--English: USA
--English: USA Legal
--English: USA Medical
--Estonian
--Finnish
--French
--French: Canadian
--German: Reformed
--German: Swiss
--German: Traditional
--Greek
--Hungarian
--Italian
--Latvian
--Lithuanian
--Neutral
--Norwegian: Bokmal
--Norwegian: Nynorsk
--Polish
--Portuguese
--Portuguese: Brazilian
--Romanian
--Russian
--Slovak
--Slovenian
--Spanish: Castilian
--Swedish
--Turkish set dictionary to "English: USA"
--platform options:
--macintosh
--pc set platform to macintosh set strip returns between lines to true set strip returns between paragraphs to true set use typographers quotes to true end tell end tell
第 4 章 テキストと組版 テキストの配置とテキスト読み込み環境設定の指定 32
タグ付きテキスト読み込み環境設定の指定方法を、次のスクリプトに示します(完全なスクリプトについて
は、TaggedTextImportPreferences を参照してください)。 tell application "Adobe InCopy CS6" tell tagged text import preferences set remove text formatting to false
--style conflict property can be:
--publication definition
--tag file definition set style conflict to publication definition set use typographers quotes to true end tell end tell
Word および RTF 読み込み環境設定の指定方法を、次のスクリプトに示します(完全なスクリプトについて
は、WordRTFImportPreferences を参照してください)。 tell application "Adobe InCopy CS6" tell word RTF import preferences
--convert page breaks property can be:
--column break
--none
--page break set convert page breaks to none
--convert tables to property can be:
--unformatted tabbed text
--unformatted table set convert tables to to Unformatted Table set import endnotes to true set import footnotes to true set import index to true set import TOC to true set import unused styles to false set preserve graphics to false set preserve local overrides to false set preserve track changes to false set remove formatting to false
--resolve character style clash and
--resolve paragraph style clash properties can be:
--resolve clash auto rename
--resolve clash use existing
--resolve clash use new set resolve character style clash to resolve clash use existing set resolve paragraph style clash to resolve clash use existing set use typographers quotes to true end tell end tell
Excel 読み込み環境設定の指定方法を、次のスクリプトに示します(完全なスクリプトについては、
第 4 章 テキストと組版 テキストの書き出しとテキスト書き出し環境設定の指定 33 tell application "Adobe InCopy CS6" tell excel import preferences
--alignment Style property can be:
--center align
--left align
--right align
--spreadsheet set alignment style to spreadsheet set decimal places to 4 set preserve graphics to false
--Enter the range you want to import as "start cell:end cell".
set range name to "A1:B16" set sheet index to 1 set sheet name to "pathpoints" set show hidden cells to false
--table formatting property can be:
--excel formatted table
--excel unformatted tabbed text
--excel unformatted table set table formatting to excel formatted table set use typographers quotes to true set view name to "" end tell end tell
テキストの書き出しとテキスト書き出し環境設定の指定
書き出すには、テキストオブジェクトやストーリーオブジェクトを使用する必要があることに注意してくだ
さい。1 つの操作でドキュメント内のすべてのテキストを書き出すことはできません (完全なスクリプトに
ついては、ExportTextFile を参照してください)。 tell application "Adobe InCopy CS6" set myDocument to make document set myStory to story 1 of myDocument
--Fill the story with placeholder text.
set myTextFrame to item 1 of text containers of myStory set contents of myTextFrame to placeholder text
--Text export method parameters:
--format as enumeration
--to alias as string
--showing options boolean
--version comments string
--force save boolean
--Format parameter can be:
--InCopy CS Document
--InCopy Document
--rtf
--tagged text
--text type
--Export the story as text. You'll have to
--fill in a valid file path on your system.
tell myStory export to "yukino:test.txt" format text type end tell end tell
指定したテキスト範囲を書き出す方法を、次の例に示します (ここでは、 myGetBounds
関数は省略していま
す。この関数については、ExportTextRange というチュートリアルスクリプトを参照してください)。
第 4 章 テキストと組版 テキストの書き出しとテキスト書き出し環境設定の指定 34 tell application "Adobe InCopy CS6" set myDocument to make document set myStory to story 1 of myDocument
--Fill the story with placeholder text.
set myTextFrame to item 1 of text containers of myStory set contents of myTextFrame to placeholder text set myStartCharacter to index of character 1 of paragraph 1 of myStory set myEndCharacter to the index of last character of paragraph 1 of myStory set myText to object reference of text from character myStartCharacter to character myEndCharacter of myStory
--Export the text range. You'll have to fill in a valid
--file path on your system.
tell myText to export to "yukino:test.txt" format text type end tell
書き出すテキストファイルの種類に応じた書き出しオプションを指定するには、対応する書き出し環境設定
オブジェクトを使用します。 テキスト書き出し環境設定を指定する方法を、次のスクリプトに示します(完
全なスクリプトについては、TextExportPreferences を参照してください)。 tell application "Adobe InCopy CS6" tell text export preferences
--Options for character set:
--UTF8
--UTF16
--default platform set character set to UTF16
--platform options:
--macintosh
--pc set platform to macintosh end tell end tell
タグ付きテキスト書き出し環境設定を指定する方法を、次のスクリプトに示します(完全なスクリプトにつ
いては、TaggedTextExportPreferences を参照してください)。 tell application "Adobe InCopy CS6" tell tagged text export preferences
--Options for character set:
--ansi
--ascii
--gb18030
--ksc5601
--shiftJIS
--UTF8
--UTF16 set character set to UTF16
--tag form options:
--abbreviated
--verbose set tag form to verbose end tell end tell
既存の書き出しフィルターを使用しないでテキストを書き出すこともできます。 AppleScript には、テキスト
ファイルをディスクに書き出す機能が用意されています。この機能を利用すれば、スクリプトでドキュメン
ト内のテキストをスキャンして、任意のテキストマークアップスキームを使用して任意の順序でテキストを
書き出すことができます。 HTML 形式で InCopy テキストを書き出す簡単な例を次に示します(完全なスクリ
プトについては、ExportHTML を参照してください)。
第 4 章 テキストと組版 テキストの書き出しとテキスト書き出し環境設定の指定 35 on mySnippet() tell application "Adobe InCopy CS6"
--Use the myStyleToTagMapping array to set up your
--paragraph style to tag mapping.
set myStyleToTagMapping to {}
--For each style to tag mapping, add a new item to the array.
copy {"body_text", "p"} to end of myStyleToTagMapping copy {"heading1", "h1"} to end of myStyleToTagMapping copy {"heading2", "h3"} to end of myStyleToTagMapping copy {"heading3", "h3"} to end of myStyleToTagMapping
--End of style to tag mapping.
if (count documents) is not equal to 0 then set myDocument to document 1 if (count stories of myDocument) is not equal to 0 then
--Open a new text file.
set myTextFile to choose file name with prompt "Save HTML As"
--Iterate through the stories.
repeat with myCounter from 1 to (count stories of myDocument) set myStory to story myCounter of myDocument repeat with myParagraphCounter from 1 to
(count paragraphs of myStory) set myParagraph to object reference of paragraph myParagraphCounter of myStory if (count tables of myParagraph) is 0 then
--If the paragraph is a simple paragraph--no tables,
--no local formatting--then simply export the text of the
--pararaph with the appropriate tag.
if (count text style ranges of myParagraph) is 1 then set myTag to my myFindTag(name of applied paragraph style of myParagraph, myStyleToTagMapping)
--If the tag comes back empty, map it to the
--basic paragraph tag.
if myTag = "" then set myTag to "p" end if set myStartTag to "<" & myTag & ">" set myEndTag to "</" & myTag & ">"
--If the paragraph is not the last paragraph
--in the story,omit the return character.
if the contents of character -1 of myParagraph is return then set myText to object reference of text from character 1 to character -2 of myParagraph set myString to contents of myText else set myString to contents of myParagraph end if
--Write the text of the paragraph to the text file.
if myParagraphCounter = 1 then set myAppendData to false else set myAppendData to true end if my myWriteToFile(myStartTag & myString & myEndTag & return, myTextFile, myAppendData) else
--Handle text style range export by iterating through
--the text style ranges in the paragraph..
repeat with myRangeCounter from 1 to (count text style ranges of myParagraph)
第 4 章 テキストと組版 テキストの書き出しとテキスト書き出し環境設定の指定 36 set myTextStyleRange to object reference of text style range myRangeCounter of myParagraph if character -1 of myTextStyleRange is return then set myText to object reference of text from character 1 to character -2 of myTextStyleRange set myString to contents of myText else set myString to contents of myText end if if font style of myTextStyleRange is "Bold" then set myString to "<b>" & myString & "</b>" else if font style of myTextStyleRange is "Italic" then set myString to "<i>" & myString & "</i>" end if my myWriteToFile(myString, myTextFile, true) end repeat my myWriteToFile(return, myTextFile, true) end if else
--Handle table export (assumes that there is only one
--table per paragraph,and that the table is in the
--paragraph by itself).
set myTable to table 1 of myParagraph my myWriteToFile("<table border = 1>", myTextFile, true) repeat with myRowCounter from 1 to (count rows of myTable) my myWriteToFile("<tr>", myTextFile, true) repeat with myColumnCounter from 1 to (count columns of myTable) if myRowCounter = 0 then set myString to "<th>" set myString to myString & text of cell myColumnCounter of row myRowCounter of myTable set myString to myString & "</th>" else set myString to "<td>" set myString to myString & text of cell myColumnCounter of row myRowCounter of myTable set myString to myString & "</td>" end if my myWriteToFile(myString, myTextFile, true) end repeat my myWriteToFile("</tr>" & return, myTextFile, true) end repeat end if end if end tell end mySnippet my myWriteToFile("</table>" & return, myTextFile, true) end if end repeat end repeat on myFindTag(myStyleName, myStyleToTagMapping) local myTag, myDone, myStyleName set myTag to "" set myDone to false repeat with myStyleToTagMap in myStyleToTagMapping
第 4 章 テキストと組版 テキストオブジェクト 37 if item 1 of myStyleToTagMap = myStyleName then set myTag to item 2 of myStyleToTagMap exit repeat end if end repeat return myTag end myFindTag on myWriteToFile(myString, myFileName, myAppendData) set myTextFile to open for access myFileName with write permission if myAppendData is false then set eof of myTextFile to 0 end if write myString to myTextFile starting at eof close access myTextFile end myWriteToFile
テキストオブジェクト
次の図は、InCopy のテキストオブジェクトモデルを図式化したものです。 テキストオブジェクトにはレイア
ウトオブジェクト(テキストフレーム)とテキストストリームオブジェクト(ストーリー、挿入点、文字、
単語など)の 2 つの種類があります。 この図では、各オブジェクトの一般的な呼び名を記載しています。ス
クリプトを作成する際は、使用するスクリプト言語で定義されている対応する用語を使用してください。 document story spread, page, layer insertion points characters words lines paragraphs text columns text style ranges texts notes text containers text frame insertion points characters words lines paragraphs text columns text style ranges texts notes
テキストストリームオブジェクトの parent
は、そのオブジェクトが含まれているストーリーです。
オブジェクトが含まれているテキストフレーム(またはテキストフレームのコレクション)への参照を取得
するには、 parent text frames
プロパティを使用します。
テキストフレームの parent
は、通常、そのテキストフレームが含まれているページまたはスプレッドです。
グループ内にあるテキストフレームや、別のページアイテム内にペーストされたテキストフレームの parent
は、そのテキストフレームが含まれているページアイテムです。 アンカー付きフレームに変換されたテキス
トフレームの parent
は、そのアンカー付きフレームが含まれている文字です。
第 4 章 テキストと組版
選択
テキストオブジェクト 38
のの種類を判別する方法を、次のスクリプトに示します。 他の多くのサンプルスクリプトと異なり、このス
クリプトは実際には何も行いません。このスクリプトでは、選択をフィルタリングする方法のみが示されて
います (完全なスクリプトについては、TextSelection を参照してください)。 tell application "Adobe InCopy CS6" if (count documents) is not equal to 0 then
--If the selection contains more than one item, the selection
--is not text selected with the Type tool.
set mySelection to selection if (count mySelection) is not equal to 0 then
--Evaluate the selection based on its type.
set myTextClasses to {insertion point, word, text style range, line, paragraph, text column, text, story} if class of item 1 of selection is in myTextClasses then
--The object is a text object; display the text object type.
--A practical script would do something with the selection,
--or pass the selection on to a function.
display dialog ("Selection is a text object.")
--If the selection is inside a note, the parent of the selection
--will be a note object.
if class of parent of item 1 of selection is note then display dialog ("Selection is inside a note.") end if end if else display dialog ("Please select some text and try again.") end if else display dialog ("No documents are open.") end if end tell
テキストの移動とコピー
move
テキ
ストをコピーするには、 duplicate
メソッドを使用します(パラメーターは move
メソッドと同じです)
スクリプトにその例を示します(完全なスクリプトについては、MoveText を参照してください)。
第 4 章 テキストと組版 テキストオブジェクト 39 tell application "Adobe InCopy CS6" set myDocument to make document
--Create a series of paragraphs in the default story.
set myStory to story 1 of myDocument set contents of myStory to "WordA" & return & "WordB" & return &
"WordC" & return & "WordD" tell myStory
--Move WordC before WordA.
move paragraph 3 to before paragraph 1
--Move WordB after WordD (into the same paragraph).
move paragraph 3 to after word 1 of paragraph -1
--Note that moving text removes it from its original location.
end tell end tell
フォーマットされたテキストをドキュメント間で転送する場合にも、 move
して貼り付けるよりも、 move
メソッドや duplicate
メソッドを使用するほうが優れています。コピーして貼
り付けるためには、ドキュメントを表示して、コピーするテキストを選択しなければなりません。 move
や duplicate
を使用するほうが速くて確実です。 move
や duplicate
を使用して、ドキュメント間でテキストを
移動する方法を、次のスクリプトに示します(完全なスクリプトについては、MoveTextBetweenDocuments
を参照してください)。 tell application "Adobe InCopy CS6" set mySourceDocument to make document
--Add text to the default story.
set mySourceStory to story 1 of mySourceDocument set contents of mySourceStory to "This is the source text." & return &
"This text is not the source text." set point size of paragraph 1 of mySourceStory to 24
--Create a new document to move the text to.
set myTargetDocument to make document set myTargetStory to story 1 of myTargetDocument set contents of myTargetStory to "This is the target text.
Insert the source text after this paragraph." & return duplicate paragraph 1 of mySourceStory to after insertion point -1 of myTargetStory end tell
フォーマットされていないテキストをテキストオブジェクト間でコピーする方法としては、コピーするテキ
ストオブジェクトの contents
プロパティを取得して、その文字列を別のテキストオブジェクトの contents
プロパティに設定する方法があります。 次のスクリプトにその例を示します(完全なスクリプトについては、
第 4 章 テキストと組版 テキストオブジェクト 40 tell application "Adobe InCopy CS6" set myDocument to make document set myStory to story 1 of myDocument set myString to "This is a formatted string." & return set myString to myString & "Text pasted after this text will retain its formatting." & return set myString to myString & "Text moved to the following line will take on the formatting of the insertion point." & return set myString to myString & "Italic: " & return set contents of myStory to myString
--Apply formatting to the first paragraph.
set font style of paragraph 1 of myStory to "Bold"
--Apply formatting to the last paragraph.
set font style of paragraph -1 of myStory to "Italic"
--Copy from one frame to another using a simple copy.
select word 1 of paragraph 1 of myStory copy select insertion point -1 of paragraph 2 of myStory paste
--Copy the unformatted string from the first word to the end of the story
--by getting and setting the contents of text objects. Note that this
--doesn't really copy the text it replicates the text string from one text
--location to another.
set contents of insertion point -1 of myStory to contents of word 1 of paragraph 1 of myStory end tell
テキストオブジェクトと反復処理
一連のテキストオブジェクトに対して繰り返して処理を行っている間に、テキストの移動、削除、追加を行
うと、テキスト参照に問題が発生することがあります。 このような問題が発生する例を、次のスクリプトに
示します(完全なスクリプトについては、TextIterationWrong を参照してください)。
--Shows how *not* to iterate through text.
tell application "Adobe InCopy CS6" set myDocument to make document set myString to "Paragraph 1.
Delete this paragraph.
Paragraph 2.
Paragraph 3.
Paragraph 4.
Paragraph 5.
Delete this paragraph.
Paragraph 6.
" set myStory to story 1 of myDocument set contents of myStory to myString
--The following for loop will fail to format all of the paragraphs
--and then generate an error.
repeat with myParagraphCounter from 1 to (count paragraphs of myStory) if contents of word 1 of paragraph myParagraphCounter of myStory is
"Delete" then tell paragraph myParagraphCounter of myStory to delete else set point size of paragraph myParagraphCounter of myStory to 24 end if end repeat end tell
第 4 章 テキストと組版 テキストのフォーマット 41
この例では、フォーマットされない段落がいくつか発生することになります。 その理由は次のとおりです。 こ
のスクリプトのループは、ストーリー内の最初の段落から最後の段落まで、段落に対して繰り返し処理を行
が削除されると、第 3 段落がその場所に移動します。 次にループカウンターが 3 になると、先ほどまで第 4 段
落であった段落が処理されます。第 3 段落であった段落はこの時点で第 2 段落になっているので、処理は行
われません。
この問題を回避するには、次のスクリプトのように、テキストオブジェクトを逆順で処理します(チュート
リアルスクリプトの TextIterationRight より)。
--Shows the correct way to iterate through text.
tell application "Adobe InCopy CS6" set myDocument to make document set myString to "Paragraph 1.
Delete this paragraph.
Paragraph 2.
Paragraph 3.
Paragraph 4.
Paragraph 5.
Delete this paragraph.
Paragraph 6.
" set myStory to story 1 of myDocument set contents of myStory to myString
--The following for loop will format all of the paragraphs by iterating
--backwards through the paragraphs in the story.
repeat with myParagraphCounter from (count paragraphs of myStory) to 1 by -1 if contents of word 1 of paragraph myParagraphCounter of myStory is
"Delete" then tell paragraph myParagraphCounter of myStory to delete else set point size of paragraph myParagraphCounter of myStory to 24 end if end repeat end tell
テキストのフォーマット
前の節では、ドキュメントにテキストを追加し、ストーリーやテキストオブジェクトを操作しました。 この
節では、テキストにフォーマットを適用します。 InCopy のすべてのフォーマット機能は、スクリプティング
で操作することができます。
テキストデフォルトの設定
テキストデフォルトは、アプリケーションとドキュメントの両方で設定できます。 アプリケーションのテキ
ストデフォルトは、新しく作成されるすべてのドキュメントのテキストデフォルトとして使用されます。 ド
キュメントのテキストデフォルトは、そのドキュメントで新しく作成されるすべてのテキストオブジェクト
のフォーマットとして使用されます (完全なスクリプトについては、TextDefaults を参照してください)。
第 4 章 テキストと組版 テキストのフォーマット 42 tell application "Adobe InCopy CS6" set horizontal measurement units of view preferences to points set vertical measurement units of view preferences to points
--To set the text formatting defaults for a document, replace "app"
--in the following lines with a reference to a document.
tell text defaults set alignToBaseline to true
--Because the font might not be available, it's usually best
--to apply the font within a try...catch structure. Fill in the
--name of a font on your system.
try set appliedFont to font "Minion Pro" end try
--Because the font style might not be available, it's usually best
--to apply the font style within a try...catch structure.
try set font style to "Regular" end try
--Because the language might not be available, it's usually best
--to apply the language within a try...catch structure.
try set applied language to "English: USA" end try set autoLeading to 100 set balsanceRaggedLines to false set baselineShift to 0 set capitalization to normal set composer to "Adobe Paragraph Composer" set desiredGlyphScaling to 100 set desiredLetterSpacing to 0 set desiredWordSpacing to 100 set drop cap characters to 0 if drop cap characters is not equal to 0 then dropCapLines to 3
--Assumes that the application has a default character style named "myDropCap" set drop cap style to character style "myDropCap" end if set fill color to "Black" set fill tint to 100 set first line indent to 14 set grid align first line only to false set horizontal scale to 100 set hyphenate after first to 3 set hyphenate before last to 4 set hyphenate capitalized words to false set hyphenate ladder limit to 1 set hyphenate words longer than to 5 set hyphenation to true set hyphenation zone to 36 set hyphen weight to 9 set justification to left align set keep all lines together to false set keep lines together to true set keep first lines to 2 set keep last lines to 2 set keep with next to 0 set kerning method to "Optical" set leading to 14 set left indent to 0
第 4 章 テキストと組版 set ligatures to true set maximum glyph scaling to 100 set maximum letter spacing to 0 set maximum word spacing to 160 set minimum glyph scaling to 100 set minimum letter spacing to 0 set minimum word spacing to 80 set no break to false set OTF contextual alternate to true set OTF discretionary ligature to false set OTF figure style to proportional oldstyle set OTF fraction to true set OTF historical to false set OTF ordinal to false set OTF slashed zero to false set OTF swash to false set OTF titling to false set overprint fill to false set overprint stroke to false set pointSize to 11 set position to normal set right indent to 0 set rule above to false if rule above = true then set rule above color to color "Black" set rule above gap color to swatch "None" set rule above gap overprint to false set rule above gap tint to 100 set rule above left indent to 0 set rule above line weight to 0.25
set rule above offset to 14 set rule above overprint to false set rule above right indent to 0 set rule above tint to 100 set rule above type to stroke style "Solid" set rule above width to column width end if set rule below to false if rule below = true then set rule below color to color "Black" set rule below gap color to swatch "None" set rule below gap overprint to false set rule below gap tint to 100 set rule below left indent to 0 set rule below line weight to 0.25
set rule below offset to 14 set rule below overprint to false set rule below right indent to 0 set rule below tint to 100 set rule below type to stroke style "Solid" set rule below width to column width end if set single word justification to left align set skew to 0 set space after to 0 set space before to 0 set start paragraph to anywhere set strike thru to false if strike thru = true then set strike through color to color "Black"
テキストのフォーマット 43
第 4 章 テキストと組版 テキストのフォーマット 44 set strike through gap color to swatch "None" set strike through gap overprint to false set strike through gap tint to 100 set strike through offset to 3 set strike through overprint to false set strike through tint to 100 set strike through type to stroke style "Solid" set strike through weight to 0.25
end if set stroke color to "None" set stroke tint to 100 set stroke weight to 0 set tracking to 0 set underline to false if underline = true then set underline color to color "Black" set underline gap color to swatch "None" set underline gap overprint to false set underline gap tint to 100 set underline offset to 3 set underline overprint to false set underline tint to 100 set underline type to stroke style "Solid" set underline weight to 0.25
end if set vertical scale to 100 end tell end tell
フォント
InCopy アプリケーションオブジェクトのフォントコレクションには、InCopy で利用できるすべてのフォント
が含まれています。 これとは対照的に、ドキュメントのフォントコレクションには、そのドキュメントで使
用されているフォントのみが含まれています。 ドキュメントのフォントコレクションには、環境に無いフォ
ント(ドキュメントで使用されているが InCopy では利用できないフォント)も含まれます。 アプリケーショ
ンフォントとドキュメントフォントの違いを調べる方法を、次のスクリプトに示します(完全なスクリプト
については、FontCollections を参照してください)。 tell application "Adobe InCopy CS6" set myApplicationFonts to the name of every font set myDocument to make document tell myDocument set myStory to story 1 of myDocument set myDocumentFonts to name of every font if (count of fonts) > 0 then set myDocumentFonts to name of every font end if end tell set myString to "Document Fonts:" & return repeat with myCounter from 1 to (count myDocumentFonts) set myString to myString & (item myCounter) of myDocumentFonts & return end repeat set myString to myString & return & "Application Fonts:" & return repeat with myCounter from 1 to (count myApplicationFonts) set myString to myString & (item myCounter) of myApplicationFonts & return end repeat set contents of myStory to myStringend tell
第 4 章 テキストと組版 テキストのフォーマット 45
注意 : フォント名は通常、
familyName<tab>fontStyle
という形式で示されます。
familyName
はフォントファ
ミリー名、
<tab>
はタブ文字、
fontStyle
次に例を示します。
"Adobe Caslon Pro<tab>Semibold Italic"
フォントの適用
テキストのある範囲にローカルフォントを適用するには、 appliedFont
プロパティを使用します。次のスク
リプトにその例を示します(チュートリアルスクリプトの ApplyFont より)。
--Given a font name "myFontName" and a text object "myText"..
set applied font of myText to myFontName
また、次のスクリプトのように、フォントファミリー名とフォントスタイルを指定してフォントを適用する
こともできます。 set applied font of myText to "Adobe Caslon Pro" set font style of myText to "Semibold Italic"
テキストプロパティの変更
InCopy のテキストオブジェクトには、そのフォーマット属性に対応する多数のプロパティが用意されていま
いる段落とほぼ同じプロパティ)が用意されています。 SetTextProperties というチュートリアルスクリプトに
は、テキストオブジェクトのすべてのプロパティを設定する方法が示されています。 次のスクリプトにその
例を示します。
--Shows how to set all read/write properties of a text object.
tell application "Adobe InCopy CS6" set myDocument to make document set myStory to story 1 of myDocument set contents of myStory to "x" tell character 1 of myStory set align to baseline to false set applied character style to character style "[None]" of myDocument set applied font to "Minion ProRegular" set applied language to "English: USA" set applied numbering list to "[Default]" set applied paragraph style to paragraph style "[No Paragraph Style]" of myDocument set auto leading to 120 set balance ragged lines to no balancing set baseline shift to 0 set bullets alignment to left align
第 4 章 テキストと組版 テキストのフォーマット 46 set bullets and numbering list type to no list set bullets character style to character style "[None]" of myDocument set bullets text after to "^t" set capitalization to normal set composer to "Adobe Paragraph Composer" set desired glyph scaling to 100 set desired letter spacing to 0 set desired word spacing to 100 set drop cap characters to 0 set drop cap lines to 0 set drop cap style to character style "[None]" of myDocument set dropcap detail to 0
--More text properties in the tutorial script.
end tell end tell
テキストカラーの変更
テキスト文字の塗りと線にカラーを適用できます。次のスクリプトにその例を示します(チュートリアルス
クリプトの TextColors より)。 my main() on main() my mySetup() my mySnippet() end main on mySetup() tell application "Adobe InCopy CS6"
--Create an example document.
set myDocument to make document
--Create a color.
try set myColorA to color "DGC1_664a" of myDocument on error set myColorA to make color with properties
{name:"DGC1_664a", model:process, color value:{90, 100, 70, 0}} end try
--Create another color.
try set myColorB to color "DGC1_664b" of myDocument on error set myColorB to make color with properties
{name:"DGC1_664b", model:process, color value:{70, 0, 30, 50}} end try set myStory to story 1 of myDocument
--Enter text in the text frame.
set contents of myStory to "Text" & return & "Color" end tell end mySetup on mySnippet() tell application "Adobe InCopy CS6" set myDocument to document 1 set myStory to story 1 of myDocument set myColorA to color "DGC1_664a" of myDocument set myColorB to color "DGC1_664b" of myDocument tell paragraph 1 of myStory set point size to 72
第 4 章 テキストと組版 テキストのフォーマット 47 set justification to center align
--Apply a color to the fill of the text.
set fill color to myColorA set stroke color to myColorB end tell tell paragraph 2 of myStory set stroke weight to 3 set point size to 144 set justification to center align set fill color to myColorB set stroke color to myColorA set stroke weight to 3 end tell end tell end mySnippet
スタイルの作成と適用
前述のいくつかの例でローカルフォーマットを適用する方法を示しましたが、ここでは、文字スタイルや段
落スタイルを使用してテキストをフォーマットする方法について説明します。 スタイルを使用すると、
フォーマットされたテキストとスタイルの間にリンクが作成されます。そのため、スタイルの再定義、特定
のスタイルでフォーマットされたテキストの収集、テキストの検索や変更などが簡単に行えます。 段落スタ
イルや文字スタイルは、テキストのフォーマット作業を効率化する上で重要な役割を果たします。段落と文
字スタイルはテキストにフォーマットを設定する場合に生産性の鍵となるものであり、テキストにフォー
マットを適用するどんなスクリプトにとっても中心的な存在になるはずです。
段落スタイルや文字スタイルを作成して適用する方法を、次のスクリプトに示します(完全なスクリプトに
ついては、CreateStyles を参照してください)。 tell application "Adobe InCopy CS6"
--Create an example document.
set myDocument to make document tell myDocument
--Create a color for use by one of the paragraph styles we'll create.
try set myColor to color "Red" on error
--The color did not exist, so create it.
set myColor to make color with properties {name:"Red", model:process, color value:{0, 100, 100, 0}} end try set myStory to story 1 set contents of myStory to "Normal text.
Text with a character style applied to it. More normal text."
--Create a character style named "myCharacterStyle" if
--no style by that name already exists.
try set myCharacterStyle to character style "myCharacterStyle" on error
--The style did not exist, so create it.
set myCharacterStyle to make character style with properties
{name:"myCharacterStyle"} end try
--At this point, the variable myCharacterStyle contains
--a reference to a character
--style object, which you can now use to specify formatting.
set fill color of myCharacterStyle to myColor
--Create a paragraph style named "myParagraphStyle" if
--no style by that name already exists.
try
第 4 章 テキストと組版 テキストのフォーマット 48 set myParagraphStyle to paragraph style "myParagraphStyle" on error
--The paragraph style did not exist, so create it.
set myParagraphStyle to make paragraph style with properties
{name:"myParagraphStyle"} end try
--At this point, the variable myParagraphStyle contains
--a reference to a paragraph style object, which you can now use to
--specify formatting. (Note that the story object does not have the apply
--paragraph style method.) tell text 1 of story 1 apply paragraph style using myParagraphStyle tell text from character 13 to character 54 apply character style using myCharacterStyle end tell end tell end tell end tell
テキストオブジェクトの applied paragraph style
プロパティを使用せずに apply paragraph style
メソッド
を使用する利点は、 既存のフォーマットをオーバーライドできる点にあります。スタイルにプロパティを設
定しても、ローカルフォーマットは変更されずに保持されます。
新規ドキュメントの作成時に、スタイルが存在するかどうかを確認しているのは、 アプリケーションのデ
フォルトスタイルとして同じ名前のスタイルが存在している可能性があるからです。 その場合、同じ名前で
新しいスタイルを作成しようとするとエラーが発生します。
先頭文字スタイル(Nested Style)を使用すると、文字スタイルのフォーマットを特定のパターンに従って段
落に適用することができます。 先頭文字スタイルを含む段落スタイルの作成方法を、次のスクリプトに示し
ます(完全なスクリプトについては、NestedStyles を参照してください)。 tell application "Adobe InCopy CS6"
--Create an example document.
set myDocument to make document tell myDocument
--Create a color for use by one of the paragraph styles we'll create.
try set myColor to color "Red" on error
--The color did not exist, so create it.
set myColor to make color with properties
{name:"Red", model:process, color value:{0, 100, 100, 0}} end try
--Create a character style named "myCharacterStyle" if
--no style by that name already exists.
try set myCharacterStyle to character style "myCharacterStyle" on error
--The style did not exist, so create it.
set myCharacterStyle to make character style with properties
{name:"myCharacterStyle"} end try
--At this point, the variable myCharacterStyle contains a
--reference to a character style object, which you can now use to specify
--formatting.
set fill color of myCharacterStyle to myColor
--Create a paragraph style named "myParagraphStyle" if
--no style by that name already exists.
try
第 4 章 テキストと組版 テキストのフォーマット 49 set myParagraphStyle to paragraph style "myParagraphStyle" on error
--The paragraph style did not exist, so create it.
set myParagraphStyle to make paragraph style with properties
{name:"myParagraphStyle"} end try
--At this point, the variable myParagraphStyle contains a reference
--to a paragraph style object. Next, add a nested style to the paragraph
--style.
tell myParagraphStyle set myNestedStyle to make nested style with properties {applied character style:myCharacterStyle, delimiter:".", inclusive:true, repetition:1} end tell
--Apply the paragraph style to the story so that we can see the
--effect of the nested style we created.
--(Note that the story object does not have the applyStyle method.) tell story 1 set myTextFrame to item 1 of text containers set contents of myTextFrame to placeholder text tell text 1 apply paragraph style using myParagraphStyle end tell end tell end tell end tell
スタイルの削除
ユーザーインターフェイスでスタイルを削除する際には、タグ付けされたスタイルでテキストのフォーマッ
ト方法を選択することができますが、 InCopy スクリプティングでもこれと同じことが行えます。次のスクリ
プトにその例を示します(チュートリアルスクリプトの RemoveStyle より)。 tell myDocument set myParagraphStyleA to paragraph style "myParagraphStyleA" set myParagraphStyleB to paragraph style "myParagraphStyleB"
--Remove the paragraph style myParagraphStyleA and replace with
--myParagraphStyleB.
delete myParagraphStyleA replacing with myParagraphStyleB end tell
段落スタイルと文字スタイルの読み込み
他の InCopy ドキュメントから文字スタイルや段落スタイルを読み込むことができます。 次のスクリプトにそ
の例を示します(完全なスクリプトについては、ImportTextStyles を参照してください)。
第 4 章 テキストと組版 テキストの検索と変更 50 tell myDocument
--Import the styles from the saved document.
--importStyles parameters:
--Format options for text styles are:
-- paragraph styles format
-- character styles format
-- text styles format
--From as file or string
--Global Strategy options are:
-- do not load the style
-- load all with overwrite
-- load all with rename import styles format text styles format from myFilePath global strategy load all with overwrite end tell
テキストの検索と変更
検索/変更機能は、テキストを操作するための最も強力なツールの 1 つであり、 スクリプティングに完全に
対応しています。スクリプトを使用すれば、ユーザーインターフェイスでは利用できない様々なオプション
が指定できます。 InCopy では、次の 3 つの方法でテキストを検索できます。
テキストやテキストフォーマットを検索して、別のテキストやテキストフォーマットに変更できます。
この場合は、 find text preferences
オブジェクトや change text preferences
オブジェクトを使用して、 find text
メソッドや change text
メソッドのパラメーターを指定します。
正規表現を使用したテキスト検索(grep)を実行できます。 この場合は、 find grep preferences
オブ
ジェクトや change grep preferences
オブジェクトを使用して、 find grep
メソッドや change grep
メソッ
ドのパラメーターを指定します。
指定された字形(とそのフォーマット)を検索して、別の字形やフォーマットに置換できます。 この場
合は、 find glyph preferences
オブジェクトや change glyph preferences
オブジェクトを使用して、 find glyph
メソッドや change glyph
メソッドのパラメーターを指定します。
どの検索/変更メソッドにも、 reverse order
という 1 つのオプションパラメーターがあります。このパラ
メーターで、検索結果を返す順序を指定できます。 検索/変更操作の結果に基づいて、ストーリーのテキス
で説明したテキス
ト参照の問題に注意する必要があります。 この問題が発生する場合は、返されたテキストオブジェクトのコ
レクションを逆順で処理するようにループを設定するか、または、検索結果を逆順で返すように設定して、
そのコレクションを通常の順序で処理します。
検索/変更の環境設定
テキストを検索する前に、検索/変更の環境設定を消去することで、前回の設定を引き継がないようにする
ことができます。 また、必要に応じていくつかの検索/変更環境設定を指定して、対象となるテキスト、
フォーマット、正規表現、字形などを指定することができます。 検索/変更操作を行う一般的な手順を次に
示します。
1.
検索/変更の環境設定を消去します。 検索/変更操作の種類に応じて、次の 3 つのいずれかを行います。
第 4 章 テキストと組版 テキストの検索と変更 51
--find/change text preferences tell application "Adobe InCopy CS6" set find text preferences to nothing set change text preferences to nothing end tell
--find/change grep preferences tell application "Adobe InCopy CS6" set find grep preferences to nothing set change grep preferences to nothing end tell
--find/change glyph preferences tell application "Adobe InCopy CS6" set find glyph preferences to nothing set change glpyh preferences to nothing end tell
2.
検索/変更のパラメーターを設定します。
3.
検索/変更操作を実行します。
4.
検索/変更の環境設定を再び消去します。
テキストの検索と変更
指定したテキスト文字列を検索する方法を、次のスクリプトに示します。 このスクリプトではドキュメント
全体を検索していますが、ストーリー、テキストフレーム、段落、テキスト列などのテキストオブジェクト
を検索することもできます。 find text
メソッドとそのパラメーターは、すべてのテキストオブジェクトで共
通しています (完全なスクリプトについては、FindText を参照してください)。
--Clear the find/change preferences.
set find text preferences to nothing set change text preferences to nothing
--Search the document for the string "Text".
set find what of find text preferences to "text"
--Set the find options.
set case sensitive of find change text options to false set include footnotes of find change text options to false set include hidden layers of find change text options to false set include locked layers for find of find change text options to false set include locked stories for find of find change text options to false set include master pages of find change text options to false set whole word of find change text options to false tell document 1 set myFoundItems to find text display dialog ("Found " & (count myFoundItems) & " instances of the search string.")
指定したテキスト文字列を検索して別の文字列に置換する方法を、次のスクリプトに示します(完全なスク
リプトについては、ChangeText を参照してください)。
第 4 章 テキストと組版 テキストの検索と変更 52
--Clear the find/change preferences.
set find text preferences to nothing set change text preferences to nothing
--Set the find options.
set case sensitive of find change text options to false set include footnotes of find change text options to false set include hidden layers of find change text options to false set include locked layers for find of find change text options to false set include locked stories for find of find change text options to false set include master pages of find change text options to false set whole word of find change text options to false
--Search the document for the string "copy" and change it to "text".
--Search the document for the string "copy".
set find what of find text preferences to "copy" set change to of change text preferences to "text" tell document 1 set myFoundItems to change text end tell display dialog ("Changed " & (count myFoundItems) & " instances of the search string.")
--Clear the find/change preferences after the search.
set find text preferences to nothing set change text preferences to nothing
フォーマットの検索と変更
テキストフォーマットの検索や変更を行うには、 findTextPreferences
オブジェクトや changeTextPreferences
オブジェクトのその他のプロパティを設定します。次のスクリプトにその例を示し
ます(チュートリアルスクリプトの FindChangeFormatting より)。
--Clear the find/change preferences.
set find text preferences to nothing set change text preferences to nothing
--Search the document for the string "Text".
set find what of find text preferences to "text"
--Set the find options.
set case sensitive of find change text options to false set include footnotes of find change text options to false set include hidden layers of find change text options to false set include locked layers for find of find change text options to false set include locked stories for find of find change text options to false set include master pages of find change text options to false set whole word of find change text options to false
--Search the document for the 24 point text and change it to 10 point text.
set point size of find text preferences to 24 set point size of change text preferences to 10 tell document 1 change text end tell
--Clear the find/change preferences after the search.
set find text preferences to nothing set change text preferences to nothing
テキスト文字列を検索してフォーマットを適用することもできます。次のスクリプトにその例を示します
(チュートリアルスクリプトの FindChangeStringFormatting より)。
第 4 章 テキストと組版 テキストの検索と変更 53
--Clear the find/change preferences.
set find text preferences to nothing set change text preferences to nothing
--Set the find options.
set case sensitive of find change text options to false set include footnotes of find change text options to false set include hidden layers of find change text options to false set include locked layers for find of find change text options to false set include locked stories for find of find change text options to false set include master pages of find change text options to false set whole word of find change text options to false set find what of find text preferences to "WIDGET^9^9^9^9"
--The following line will only work if your default font has a font style named "Bold"
--if not, change the text to a font style used by your default font.
set font style of change text preferences to "Bold"
--Search the document. In this example, we'll use the
--InCopy search metacharacter "^9" to find any digit.
tell document 1 set myFoundItems to change text end tell display dialog ("Changed " & (count myFoundItems) & " instances of the search string.")
--Clear the find/change preferences after the search.
set find text preferences to nothing set change text preferences to nothing
grep の使用
InCopy の findGrep
メソッドや changeGrep
メソッドを使用すれば、正規表現を利用した検索/変更操作が行
トのフォーマットを changeGrepPreferences
オブジェクトのプロパティで指定したフォーマットに置換する
ことができます。 これらのメソッドや関係する環境設定オブジェクトの使用方法を、次のスクリプトに示し
ます(完全なスクリプトについては、FindGrep を参照してください)。
--Clear the find/change preferences.
set find grep preferences to nothing set change grep preferences to nothing
--Set the find options.
set include footnotes of find change grep options to false set include hidden layers of find change grep options to false set include locked layers for find of find change grep options to false set include locked stories for find of find change grep options to false set include master pages of find change grep options to false
--Regular expression for finding an email address.
set find what of find grep preferences to "(?i)[A-Z0-9]*?@[A-Z0-9]*?[.]..."
--Apply the change to 24-point text only.
set point size of find grep preferences to 24 set underline of change grep preferences to true tell document 1 change grep end tell
--Clear the find/change preferences after the search.
set find grep preferences to nothing set change grep preferences to nothing
注意 : find change text options
オブジェクトで使用できる whole word
と case sensitive
の 2 つのプロパティ
は、 findChangeGrepOptions
オブジェクトでは使用できません。
ンを表現できるからです。 大文字と小文字を区別しない場合は
(?i)
を使用し、区別する場合は
(?-i)
を使用
します。 単語の先頭に一致するには
¥>
を使用し、単語の末尾に一致するには
¥<
を使用し、単語の境界に一致
するには
¥b
を使用します。
第 4 章 テキストと組版 テキストの検索と変更 54 grep 検索/変更の利用例として、マークアップテキスト(タグでフォーマットが指定されているプレーンテ
キスト)を InCopy 形式のテキストに変換する処理があります。 簡単なテキストマークアップスキームとして
は、PageMaker の段落タグがあります(これは、PageMaker のタグ付きテキスト形式のファイルとは異なり
ます)。 このスキームでマークアップされたテキストファイルでは、次の例のように、段落スタイルの名前が
段落の先頭に示されます。
<heading1>This is a heading.
<body_text>This is body text.
grep 検索とテキスト検索/変更を組み合わせれば、テキストにフォーマットを適用して、マークアップタグ
を削除することができます。次のスクリプトにその例を示します(チュートリアルスクリプトの ReadPMTags
より)。 on myReadPMTags(myStory) tell application "Adobe InCopy CS6" set myDocument to parent of myStory
--Reset the find grep preferences to ensure that
--previous settings do not affect the search.
set find grep preferences to nothing set change grep preferences to nothing
--Set the find options.
set include footnotes of find change grep options to false set include hidden layers of find change grep options to false set include locked layers for find of find change grep options to false set include locked stories for find of find change grep options to false set include master pages of find change grep options to false
--Find the tags.
set find what of find grep preferences to "(?i)^<¥¥s*¥¥w+¥¥s*>" tell myStory set myFoundItems to find grep end tell if (count myFoundItems) is not equal to 0 then set myFoundTags to {} repeat with myCounter from 1 to (count myFoundItems) set myFoundTag to contents of item myCounter of myFoundItems if myFoundTags does not contain myFoundTag then copy myFoundTag to end of myFoundTags end if end repeat
--At this point, we have a list of tags to search for.
repeat with myCounter from 1 to (count myFoundTags) set myString to item myCounter of myFoundTags
--Find the tag using find what.
set find what of find text preferences to myString
--Extract the style name from the tag.
set myStyleName to text 2 through ((count characters of myString)
-1) of myString tell myDocument
--Create the style if it does not already exist.
try set myStyle to paragraph style myStyleName on error set myStyle to make paragraph style with properties
{name:myStyleName} end try end tell
--Apply the style to each instance of the tag.
set applied paragraph style of change text preferences to myStyle tell myStory
第 4 章 テキストと組版 表 55 change text end tell
--Reset the change text preferences.
set change text preferences to nothing
--Set the change to property to an empty string.
set change to of change text preferences to ""
--Search to remove the tags.
tell myStory change text end tell
--Reset the find/change preferences again.
set change text preferences to nothing end repeat end if
--Reset the findGrepPreferences.
set find grep preferences to nothing end tell end myReadPMTags
字形検索の使用
特定のフォントに含まれている個々の文字を検索/変更するには、 find glyph
メソッドや change glyph
メ
ソッドを使用します。パラメーターは find glyph preferences
オブジェクトや change glyph preferences
オ
ブジェクトで設定します。 次のスクリプトでは、サンプルドキュメントの中で字形を検索し、変更していま
す(完全なスクリプトについては、FindChangeGlyphs を参照してください)。
--Clear glyph search preferences.
set find glyph preferences to nothing set change glyph preferences to nothing set myDocument to document 1
--You must provide a font that is used in the document for the
--applied font property of the find glyph preferences object.
set applied font of find glyph preferences to applied font of character 1 of story 1 of myDocument
--Provide the glyph ID, not the glyph Unicode value.
set glyph ID of find glyph preferences to 500
--The applied font of the change glyph preferences object can be
--any font available to the application.
set applied font of change glyph preferences to "Times New RomanRegular" set glyph ID of change glyph preferences to 374 tell myDocument change glyph end tell
--Clear glyph search preferences.
set find glyph preferences to nothing set change glyph preferences to nothing
表
convert text
to
table
メソッドを使用して、既存のテキストから表を作成したり、ストーリー内の任意の挿
入点に空の表を作成することができます。 次のスクリプトでは、3 つの異なる方法で表を作成しています(完
全なスクリプトについては、MakeTable を参照してください)。
第 4 章 テキストと組版 表 56 set myStory to story 1 of myDocument tell myStory set myStartCharacter to index of character 1 of paragraph 7 set myEndCharacter to index of character -2 of paragraph 7 set myText to object reference of text from character myStartCharacter to character myEndCharacter
--The convertToTable method takes three parameters:
--[column separator as string]
--[row separator as string]
--[number of columns as integer] (only used if the column separator
--and row separator values are the same)
--In the last paragraph in the story, columns are separated by commas
--and rows are separated by semicolons, so we provide those characters
--to the method as parameters.
tell myText set myTable to convert to table column separator "," row separator ";" end tell set myStartCharacter to index of character 1 of paragraph 2 set myEndCharacter to index of character -2 of paragraph 5 set myText to object reference of text from character myStartCharacter to character myEndCharacter
--In the second through the fifth paragraphs, colums are separated by
--tabs and rows are separated by returns. These are the default delimiter
--parameters, so we don't need to provide them to the method.
tell myText set myTable to convert to table column separator tag row separator return end tell
--You can also explicitly add a table--you don't have to convert text
--to a table.
tell insertion point -1 set myTable to make table set column count of myTable to 3 set body row count of myTable to 3 end tell end tell
表セルの結合方法を、次のスクリプトに示します(完全なスクリプトについては、MergeTableCells を参照し
てください)。 set myDocument to document 1 tell story 1 of myDocument tell table 1
--Merge all of the cells in the first column.
merge cell 1 of column 1 with cell -1 of column 1
--Convert column 2 into 2 cells (rather than 4).
merge cell 3 of column 2 with cell -1 of column 2 merge cell 1 of column 2 with cell 2 of column 2
--Merge the last two cells in row 1.
merge cell -2 of row 1 with cell -1 of row 1
--Merge the last two cells in row 3.
merge cell -2 of row 3 with cell -1 of row 3 end tell end tell
表セルの分割方法を、次のスクリプトに示します(完全なスクリプトについては、SplitTableCells を参照して
第 4 章 テキストと組版 表 57 tell table 1 of story 1 of document 1 split cell 1 using horizontal split column 1 using vertical split cell 1 using vertical split row -1 using horizontal split cell -1 using vertical
--Fill the cells with row:cell labels.
repeat with myRowCounter from 1 to (count rows) set myRow to row myRowCounter repeat with myCellCounter from 1 to (count cells of myRow) set myString to "Row: " & myRowCounter & " Cell: " & myCellCounter set contents of text 1 of cell myCellCounter of row myRowCounter to myString end repeat end repeat end tell
表にヘッダー行とフッター行を作成する方法を、次のスクリプトに示します(完全なスクリプトについては、 tell table 1 of story 1 of document 1
--Convert the first row to a header row.
set row type of row 1 to header row
--Convert the last row to a footer row.
set row type of row -1 to footer row end tell
表にフォーマットを適用する方法を、次のスクリプトに示します(完全なスクリプトについては、 set myTable to table 1 of story 1 of document 1 tell myTable
--Convert the first row to a header row.
set row type of row 1 to header row
--Use a reference to a swatch, rather than to a color.
set fill color of row 1 to swatch "DGC1_446b" of myDocument set fill tint of row 1 to 40 set fill color of row 2 to swatch "DGC1_446a" of myDocument set fill tint of row 2 to 40 set fill color of row 3 to swatch "DGC1_446a" of myDocument set fill tint of row 3 to 20 set fill color of row 4 to swatch "DGC1_446a" of myDocument set fill tint of row 4 to 40
--Use everyItem to set the formatting of multiple cells at once.
tell every cell in myTable
--myTable.cells.everyItem().topEdgeStrokeColor to myDocument.swatches.item("DGC1_446b") set top edge stroke color to swatch "DGC1_446b" of myDocument
--myTable.cells.everyItem().topEdgeStrokeWeight to 1 set top edge stroke weight to 1
--myTable.cells.everyItem().bottomEdgeStrokeColor to myDocument.swatches.item("DGC1_446b") set bottom edge stroke color to swatch "DGC1_446b" of myDocument
--myTable.cells.everyItem().bottomEdgeStrokeWeight to 1
第 4 章 テキストと組版 表 58 set bottom edge stroke weight to 1
--When you set a cell stroke to a swatch, make certain that you also set the stroke weight.
--myTable.cells.everyItem().leftEdgeStrokeColor to myDocument.swatches.item("None") set left edge stroke color to swatch "None" of myDocument
--myTable.cells.everyItem().leftEdgeStrokeWeight to 0 set left edge stroke weight to 0
--myTable.cells.everyItem().rightEdgeStrokeColor to myDocument.swatches.item("None") set right edge stroke color to swatch "None" of myDocument
--myTable.cells.everyItem().rightEdgeStrokeWeight to 0 set right edge stroke weight to 0 end tell end tell
表に反復行フォーマットを追加する方法を、次のスクリプトに示します(完全なスクリプトについては、 set myTable to table 1 of story 1 of myDocument tell myTable
--Convert the first row to a header row.
set row type of row 1 to header row
--Apply alternating fills to the table.
set alternating fills to alternating rows set start row fill color to swatch "DGC1_446a" of myDocument set start row fill tint to 60 set end row fill color to swatch "DGC1_446b" of myDocument set end row fill tint to 50 end tell
テキストや表セルが選択されている場合の選択の処理方法を、次のスクリプトに示します。 このスクリプト
では、選択状況に応じて警告を表示していますが、実際のスクリプトでは選択されているアイテムに応じて
何らかの操作を行うことになります (完全なスクリプトについては、TableSelection を参照してください)。 if (count documents) is not equal to 0 then
--If the selection contains more than one item, the selection
--is not text selected with the Type tool.
set mySelection to selection if (count mySelection) is not equal to 0 then
--Evaluate the selection based on its type.
set myTextClasses to {insertion point, word, text style range, line, paragraph, text column, text, story} if class of item 1 of selection is in myTextClasses then
--The object is a text object; display the text object type.
--A practical script would do something with the selection,
--or pass the selection on to a function.
if class of parent of item 1 of mySelection is cell then display dialog ("The selection is inside a table cell") else
第 4 章 テキストと組版 自動修正 59
自動修正
自動修正機能を使用すると、テキストが入力されたときにテキストを自動的に修正することができます。 次
のスクリプトにその例を示します(完全なスクリプトについては、Autocorrect を参照してください)。
--The autocorrect preferences object turns the
--autocorrect feature on or off.
tell application "Adobe InCopy CS6" tell auto correct preferences set autocorrect to true set auto correct capitalization errors to true
--Add a word pair to the autocorrect list. Each auto correct table
--is linked to a specific language. end tell set myAutoCorrectTable to auto correct table "English: USA"
--To safely add a word pair to the auto correct table, get the current
--word pair list, then add the new word pair to that array, and then
--set the autocorrect word pair list to the array.
set myWordPairList to auto correct word pair list of myAutoCorrectTable
--Add a new word pair to the array.
set myWordPairList to myWordPairList & {"paragarph", "paragraph"}
--Update the word pair list.
set auto correct word pair list of auto correct table "English: USA" to myWordPairList
--To clear all autocorrect word pairs in the current dictionary:
--myAutoCorrectTable.autoCorrectWordPairList to {{}} end tell
脚注
display dialog ("The selection is not in a table") end if else if class of item 1 of selection is cell then display dialog ("The selection is a table cell") else if class of item 1 of selection is row then display dialog ("The selection is a table row") else if class of item 1 of selection is column then display dialog ("The selection is a table column") else if class of item 1 of selection is table then display dialog ("The selection is a table.") else display dialog ("The selection is not in a table") end if end if end if
ストーリーに脚注を追加する方法を、次のスクリプトに示します(完全なスクリプトについては、Footnotes
を参照してください)。
第 4 章 テキストと組版 tell application "Adobe InCopy CS6" set myDocument to document 1 tell footnote options of myDocument set separator text to tab set marker positioning to superscript marker end tell set myStory to story 1 of myDocument
--Add four footnotes at random locations in the story.
local myStoryLength, myRandomNumber set myStoryLength to (count words of myStory) repeat with myCounter from 1 to 5 set myRandomNumber to my myGetRandom(1, myStoryLength) tell insertion point -1 of word myRandomNumber of myStory set myFootnote to make footnote end tell
--Note: when you create a footnote, it contains text--the footnote marker
--and the separator text (if any). If you try to set the text of the
--footnote by setting the footnote contents, you will delete the marker.
--Instead, append the footnote text, as shown below.
tell insertion point -1 of myFootnote set contents to "This is a footnote." end tell end repeat end tell end mySnippet
--This function gets a random integer in the range myStart to myEnd.
on myGetRandom(myStart, myEnd) set myRange to myEnd - myStart set myRandomInteger to (myStart + (random number from myStart to myEnd)) as integer return myRandomInteger end myGetRandom
脚注 60
5
ユーザーインターフェイス
章の更新ステータス
CS6
変更なし
のダイアログボックスか、テキストを入力するためのダイアログボックスに限られていますが、より複雑な
ダイアログボックスを使用したいこともあります。 InCopy スクリプティングを使用すれば、ポップアップリ
スト、テキスト入力フィールド、数値入力フィールドなどの一般的なユーザーインターフェイスコントロー
ルを備えたダイアログボックスを作成できます。 ユーザー(または自分)から情報を受け取って、それに基
づいて処理を実行したい場合は、 dialog
オブジェクトが役に立ちます。
この章では、InCopy のダイアログボックスを使用したスクリプトについて説明します。 最初は簡単なサンプ
ルスクリプトから始めて、徐々に複雑なスクリプトへと進んでいきます。
注意 : JavaScript で InCopy スクリプトを作成する場合は、Adobe
ScriptUI コンポーネントを使用してユーザー
インターフェイスを作成することもできます。 この章には、ScriptUI スクリプティングのチュートリアルも含
まれています。詳しくは、『Adobe Creative Suite® 5 JavaScript Tools Guide』を参照してください。
ここでは、読者が
を既に読んでおり、スクリプトを作成、インストール、実行する方法
を理解しているものとして説明を行います。
ダイアログボックスの概要
InCopy のダイアログボックスは、InCopy の他のスクリプティングオブジェクトと同じく、1 つのオブジェク
ることができます。 dialog dialog column static text border panel checkbox control radiobutton group radiobutton control measurement editbox dropdown
61
第 5 章 ユーザーインターフェイス
この図に示されている各アイテムについて、次の表で説明します。
最初の InCopy ダイアログボックスの作成 62
ダイアログボックスの要素
テキスト編集フィールド
数値入力フィールド
ポップアップメニュー
テキスト編集フィールドとポップアップメニューを
組み合わせたコントロール
チェックボックス
ラジオボタン
InCopy での名前
Text editbox control
Real editbox, integer editbox, measurement editbox, percent editbox, angle editbox
Drop-down control
Combo-box control
Check-box control
Radio-button control
これらのコントロールは、 dialog
オブジェクトに直接格納されるのではなく、 dialog column
というオブジェ
クトに格納されます。 dialog column
を使用することで、ダイアログボックス内のコントロールの位置を制御
することができます。 dialog column
の中に、別の dialog column
や border panel
を含めて、ダイアログボッ
クスをさらに細かく分割することができます(必要に応じて、 dialog column
や border panel
の中に別の dialog column
や border panel
を順次含めていくことができます)
InCopy の他のスクリプティングオブジェクトと同じように、ダイアログボックスの各パーツにも固有のプロ
パティがあります。 例えば、 checkbox control
には、表示されるテキストを表すプロパティ( static label
)
や、コントロールの状態を表すプロパティ( checked state
)があります。 また、 dropdown
コントロールに
は、メニューに表示されるオプションのリストを表すプロパティ( string list
)があります。
スクリプトの中でダイアログボックスを使用するには、まず dialog
オブジェクトを作成し、そこに様々なコ
ントロールを配置して、ダイアログボックスを表示します。そして、スクリプトの処理に必要な値をそれら
のコントロールから収集します。 ダイアログボックスは、破棄されるまで InCopy のメモリ内に維持されま
を複数のスクリプトで使用することが可能です。ただし、ダイアログボックスを保持するためにメモリが消
費されるので、必要がなくなったら破棄するようにしてください。 一般的には、スクリプトが処理を終了す
る前にダイアログボックスオブジェクトを破棄します。
最初の InCopy ダイアログボックスの作成
クスにダイアログコラムを追加し、ダイアログコラムにコントロールを追加します。 次のスクリプトにその
例を示します(完全なスクリプトについては、SimpleDialog を参照してください)。
第 5 章 ユーザーインターフェイス 「Hello World」へのユーザーインターフェイスの追加 63 tell application "Adobe InCopy CS6" set myDialog to make dialog with properties {name:"Simple Dialog"} tell myDialog tell (make dialog column) make static text with properties {static label:"This is a very simple dialog box."} end tell end tell
--Show the dialog box.
set myResult to show myDialog
--If the user clicked OK, display one message;
--if they clicked Cancel, display a different message.
if myResult is true then display dialog ("You clicked the OK button") else display dialog ("You clicked the Cancel button") end if
--Remove the dialog box from memory.
destroy myDialog end tell
「Hello World」へのユーザーインターフェイスの追加
次の例は、 第 2 章「はじめに」 で作成した Hello World チュートリアルスクリプトに、簡単なユーザーイン
ターフェイスを追加したものです。 ダイアログボックスに表示されるオプションを使用して、表示するテキ
ストを指定したり、テキストのポイントサイズを変更したりすることができます。 完全なスクリプトについ
ては、HelloWorldUI を参照してください。 tell application "Adobe InCopy CS6" set myDialog to make dialog tell myDialog set name to "Simple User Interface Example Script" set myDialogColumn to make dialog column tell myDialogColumn
--Create a text entry field.
set myTextEditField to make text editbox with properties ¬
{edit contents:"Hello World!", min width:180}
--Create a number (real) entry field.
set myPointSizeField to make real editbox with properties
{edit contents:"72"} end tell show
--Get the settings from the dialog box.
--Get the point size from the point size field.
set myPointSize to edit contents of myPointSizeField as real
--Get the example text from the text edit field.
set myString to edit contents of myTextEditField
--Remove the dialog box from memory.
destroy myDialog end tell set myDocument to make document tell story 1 of myDocument
--Apply the settings from the dialog box to the text.
set contents to myString
--Set the point size of the text.
set point size of text 1 to myPointSize end tell end tell
第 5 章 ユーザーインターフェイス さらに複雑なユーザーインターフェイスの作成 64
さらに複雑なユーザーインターフェイスの作成
次の例では、様々なコントロールをサンプルダイアログボックスに追加します。 この例では、次のようなダ
イアログボックスが作成されます。
完全なスクリプトについては、ComplexUI を参照してください。 tell application "Adobe InCopy CS6" set myDocument to make document set mySwatchNames to name of every swatch of myDocument set myDialog to make dialog
--This example dialog box uses border panels and dialog columns to
--separate and organize the user interface items in the dialog.
tell myDialog set name to "User Interface Example Script" set myDialogColumn to make dialog column tell myDialogColumn set myBorderPanel to make border panel tell myBorderPanel set myDialogColumn to make dialog column tell myDialogColumn make static text with properties {static label:"Message:"} end tell set myDialogColumn to make dialog column tell myDialogColumn set myTextEditField to make text editbox with properties
{edit contents:"Hello World!", min width:180} end tell end tell set myBorderPanel to make border panel tell myBorderPanel set myDialogColumn to make dialog column tell myDialogColumn make static text with properties {static label:"Point Size:"} end tell set myDialogColumn to make dialog column tell myDialogColumn set myPointSizeField to make real editbox with properties
{edit contents:"72"} end tell end tell set myBorderPanel to make border panel tell myBorderPanel make static text with properties { static label:"Paragraph Alignment:"} set myParagraphAlignmentGroup to make radiobutton group tell myParagraphAlignmentGroup set myLeftRadioButton to make radiobutton control with properties {static label:"Left", checked state:true} set myCenterRadioButton to make radiobutton control with properties {static label:"Center"}
第 5 章 ユーザーインターフェイス set myRightRadioButton to make radiobutton control with properties {static label:"Right"} end tell end tell set myBorderPanel to make border panel tell myBorderPanel make static text with properties {static label:"Text Color:"} set mySwatchesDropdown to make dropdown with properties
{string list:mySwatchNames, selected index:1} end tell end tell show
--Get the settings from the dialog box.
--Get the point size from the point size field.
set myPointSize to edit contents of myPointSizeField as real
--Get the example text from the text edit field.
set myString to edit contents of myTextEditField
--Get the paragraph alignment setting from the radiobutton group.
get properties of myParagraphAlignmentGroup if selected button of myParagraphAlignmentGroup is 0 then set myParagraphAlignment to left align else if selected button of myParagraphAlignmentGroup is 1 then set myParagraphAlignment to center align else set myParagraphAlignment to right align end if
--Get the text color selected in the dropdown.
set mySwatchName to item ((selected index of mySwatchesDropdown) + 1) of mySwatchNames
--Remove the dialog box from memory.
destroy myDialog end tell tell story 1 of myDocument
--Apply the settings from the dialog box to the text frame.
set contents to myString
--Apply the paragraph alignment ("justification").
--"text 1 of myStory" is all of the text in the text story.
set justification of text 1 to myParagraphAlignment
--Set the point size of the text in the text frame.
set point size of text 1 to myPointSize
--Set the fill color of the text to the selected swatch.
set fill color of text 1 to swatch mySwatchName of myDocument end tell end tell
ScriptUI の使用 65
ScriptUI の使用
JavaScript では、ScriptUI というアドビ システムズ社独自のスクリプティングコンポーネントを使用して、
ユーザーインターフェイス要素の作成や定義が行えます。 ScriptUI を使用すれば、InCopy の組み込みの dialog
オブジェクトよりも格段に複雑なインタラクティブダイアログボックスを作成できます。また、フ
ローティングパレットやプログレスバーも作成できます。
AppleScript や VBScript でも、ScriptUI を使用して定義されたユーザーインターフェイス要素にアクセスするこ
とができます。 do script メソッド(AppleScript の場合)や DoScript メソッド(VBScript の場合)を使用すれ
ば、他のスクリプト言語で書かれたスクリプトを実行できます。
第 5 章 ユーザーインターフェイス
ScriptUI の使用 66
ScriptUI を使用したプログレスバーの作成
JavaScript で ScriptUI を使用してプログレスバーを作成する方法を、次のスクリプトに示します(完全なスク
リプトについては、ProgressBar を参照してください)。このスクリプトで作成したプログレスバーは、
AppleScript や VBScript でも使用することが可能です。
#targetengine "session" var myProgressPanel; var myMaximumValue = 300; var myProgressBarWidth = 300; var myIncrement = myMaximumValue/myProgressBarWidth; myCreateProgressPanel(myMaximumValue, myProgressBarWidth); function myCreateProgressPanel(myMaximumValue, myProgressBarWidth){ myProgressPanel = new Window('window', 'Progress'); with(myProgressPanel){ myProgressPanel.myProgressBar = add('progressbar', [12, 12, myProgressBarWidth, 24], 0, myMaximumValue);
}
}
前のスクリプトで作成したプログレスバーを AppleScript で呼び出す方法を、次のスクリプトに示します(完
全なスクリプトについては、CallProgressBar を参照してください)。 tell application "Adobe InCopy CS6" set myDocument to make document
--Note that the JavaScripts must use the "session"
--engine for this to work.
set myJavaScript to "#targetengine ¥"session¥"" & return set myJavaScript to myJavaScript & "myCreateProgressPanel(100, 400);" set myJavaScript to myJavaScript & return set myJavaScript to myJavaScript & "myProgressPanel.show();" & return do script myJavaScript language javascript repeat with myCounter from 1 to 100 set myJavaScript to "#targetengine ¥"session¥"" & return set myJavaScript to myJavaScript & "myProgressPanel.myProgressBar.value" set myJavaScript to myJavaScript & "=" & myCounter & "/myIncrement;" set myJavaScript to myJavaScript & return do script myJavaScript language javascript tell insertion point -1 of story 1 of myDocument set contents to "x" end tell if myCounter = 100 then set myJavaScript to "#targetengine ¥"session¥"" & return set myJavaScript to myJavaScript &
"myProgressPanel.myProgressBar.value = 0;" & return set myJavaScript to myJavaScript & "myProgressPanel.hide();" & return do script myJavaScript language javascript close myDocument saving no end if end repeat end tell
ScriptUI を使用したボタンバーパネルの作成
スクリプトを実行するボタンが並んだフローティングパレットも、JavaScript と ScriptUI を使用して作成する
ことができます。 実行するスクリプトはどの言語であってもかまいません。
簡単なフローティングパネルの作成方法を、次のチュートリアルスクリプトに示します。 パネルには一連の
ボタンが配置され、各ボタンはディスク上のスクリプトに関連付けられています。 ボタンをクリックすると
スクリプトが実行されます(このスクリプトで、ダイアログボックスや他のユーザーインターフェイス要素
(完全なスクリプトについては、ButtonBar を参照してください)。
第 5 章 ユーザーインターフェイス
ScriptUI の使用 67
このチュートリアルスクリプトは、次の形式の XML ファイルを読み込みます。
<buttons>
<button>
<buttonType></buttonType>
<buttonName></buttonName>
<buttonFileName></buttonFileName>
<buttonIconFile></buttonIconFile>
</button>
...
</buttons>
次に例を示します。
<buttons>
<button>
<buttonType>text</buttonType>
<buttonName>FindChangeByList</buttonName>
<buttonFileName>/c/buttons/FindChangeByList.jsx</buttonFileName>
<buttonIconFile></buttonIconFile>
</button>
<button>
<buttonType>text</buttonType>
<buttonName>SortParagraphs</buttonName>
<buttonFileName>/c/buttons/SortParagraphs.jsx</buttonFileName>
<buttonIconFile></buttonIconFile>
</button>
</buttons>
XML ファイルを読み込んでボタンバーをセットアップする関数は、次のとおりです。
#targetengine "session" var myButtonBar; main(); function main(){ myButtonBar = myCreateButtonBar(); myButtonBar.show();
} function myCreateButtonBar(){ var myButtonName, myButtonFileName, myButtonType, myButtonIconFile, myButton; var myButtons = myReadXMLPreferences(); if(myButtons != ""){ myButtonBar = new Window('window', 'Script Buttons', undefined,
{maximizeButton:false, minimizeButton:false}); with(myButtonBar){ spacing = 0; margins = [0,0,0,0]; with(add('group')){ spacing = 2; orientation = 'row'; for(var myCounter = 0; myCounter < myButtons.length(); myCounter++){ myButtonName = myButtons[myCounter].xpath("buttonName"); myButtonType = myButtons[myCounter].xpath("buttonType"); myButtonFileName = myButtons[myCounter].xpath("buttonFileName"); myButtonIconFile = myButtons[myCounter].xpath("buttonIconFile"); if(myButtonType == "text"){ myButton = add('button', undefined, myButtonName);
第 5 章 ユーザーインターフェイス
} else{ myButton = add('iconbutton', undefined,
File(myButtonIconFile));
} myButton.scriptFile = myButtonFileName; myButton.onClick = function(){ myButtonFile = File(this.scriptFile) app.doScript(myButtonFile);
}
}
}
}
} return myButtonBar;
} function myReadXMLPreferences(){ myXMLFile = File.openDialog("Choose the file containing your button bar defaults"); var myResult = myXMLFile.open("r", undefined, undefined); var myButtons = ""; if(myResult == true){ var myXMLDefaults = myXMLFile.read(); myXMLFile.close(); var myXMLDefaults = new XML(myXMLDefaults); var myButtons = myXMLDefaults.xpath("/buttons/button");
} return myButtons;
}
ScriptUI の使用 68
6
メニュー
章の更新ステータス
CS6
変更なし
InCopy スクリプティングでは、メニュー項目の追加と削除、任意のメニューコマンドの実行、メニュー項目
へのスクリプトの割り当てを行うことができます。
この章では、InCopy のメニューをスクリプトで操作する方法について説明します。 最初は簡単なサンプルス
クリプトから始めて、徐々に複雑なスクリプトへと進んでいきます。
ここでは、読者が
を既に読んでおり、スクリプトを作成、インストール、実行する方法
を理解しているものとして説明を行います。
メニューモデルについて
InCopy のメニュースクリプトモデルは、アプリケーションのユーザーインターフェイスに表示されるメ
ニューに対応する一連のオブジェクトによって構成されています(メインのメニューバーに表示されるメ
ニューだけでなく、パネルに用意されているメニューも含みます)。
オブジェクトには、次のオブジェク
トが含まれています。
menu items
— メニューに表示されるメニューオプション (サブメニューは含まれません)
menu separators
— メニュー内のメニューオプションを区切るために使用される線
submenus
— 更なるメニュー選択が含まれているメニューオプション
menu elements
— メニューに表示されるすべての menu items
、 menu separators
、 submenus
event listeners
— メニューに対するユーザーアクションやスクリプトアクションに応答するためのリ
スナー
events
— メニューによって発生した events
どの menu item
にも、 associated menu action
というプロパティによって menu action
が割り当てられていま
す。 menu action
のプロパティによって定義されています。
ユーザーインターフェイスで定義されている menu action
に加えて、独自の script menu action
を作成して、
メニュー項目にスクリプトを割り当てることができます。
1 つの menu action
や script menu action
は、0 個以上の menu item
に関連付けることができます。
次の図に、様々なメニューオブジェクトの関係を示します。
69
第 6 章 メニュー メニューモデルについて 70 application menuActions menuAction area checked enabled eventListeners id index label name events parent title scriptMenuActions scriptMenuAction same as menuAction eventListener eventListener
...
event event
...
表示可能なすべてのメニューアクションのリスト(テキストファイル)を作成するには、次のスクリプトを
実行します(チュートリアルスクリプトの GetMenuActions より)。 set myTextFile to choose file name("Save menu action names as:") if myTextFile is not equal to "" then tell application "Adobe InCopy CS6" set myString to "" set myMenuActionNames to name of every menu action repeat with myMenuActionName in myMenuActionNames set myString to myString & myMenuActionName & return end repeat my myWriteToFile(myString, myTextFile, false) end tell end if on myWriteToFile(myString, myFileName, myAppendData) set myTextFile to open for access myFileName with write permission if myAppendData is false then set eof of myTextFile to 0 end if write myString to myTextFile starting at eof close access myTextFile end myWriteToFile
第 6 章 メニュー メニューモデルについて 71
利用可能なメニューのリスト(テキストファイル)を作成するには、次のスクリプトを実行します(完全な
スクリプトについては、GetMenuNames というチュートリアルスクリプトを参照してください)。 InCopy には
多数のメニューがあるので、このスクリプトの実行には時間がかかる場合があります。
--Open a new text file.
set myTextFile to choose file name ("Save Menu Action Names As")
--If the user clicked the Cancel button, the result is null.
if (myTextFile is not equal to "") then tell application "Adobe InDesign CS6"
--Open the file with write access.
my myWriteToFile("Adobe InDesign CS6 Menu Names" & return, myTextFile, false) repeat with myCounter from 1 to (count menus) set myMenu to item myCounter of menus set myString to "----------" & return & name of myMenu & return &
"----------" & return set myString to my myProcessMenu(myMenu, myString) my myWriteToFile(myString, myTextFile, true) end repeat display dialog ("done!") end tell end if on myProcessMenu(myMenu, myString) tell application "Adobe InDesign CS6" set myIndent to my myGetIndent(myMenu) repeat with myCounter from 1 to (count menu elements of myMenu) set myMenuElement to menu element myCounter of myMenu set myClass to class of myMenuElement if myClass is not equal to menu separator then set myMenuElementName to name of myMenuElement set myString to myString & myIndent & myMenuElementName & return if class of myMenuElement is submenu then if myMenuElementName is not "Font" then set myString to my myProcessMenu(myMenuElement, myString) end if end if end if end repeat return myString end tell end myProcessMenu on myGetIndent(myObject) tell application "Adobe InDesign CS6" set myString to "" repeat until class of myObject is menu set myString to myString & tab set myObject to parent of myObject end repeat return myString end tell end myGetIndent on myWriteToFile(myString, myFileName, myAppendData) set myTextFile to open for access myFileName with write permission if myAppendData is false then set eof of myTextFile to 0 end if write myString to myTextFile starting at eof close access myTextFile end myWriteToFile
第 6 章 メニュー スクリプトからのメニューアクションの実行 72
ローカライゼーションとメニュー名
InCopy スクリプティングでは、 menu item
、 menu
、 menu action
、 submenu
はすべて名前で参照されます。
がって、アプリケーションがインストールされているロケールに依存せずにオブジェクトを指定する方法が
必要になります。 これを行うには、ロケールに依存せずに特定の項目を参照するための文字列が格納されて
いる内部データベースを使用します。 例えば、次のスクリプトを使用すれば、ロケールに依存しないメ
ニューアクション名を取得することができます(完全なスクリプトについては、GetKeyStrings を参照してく tell application "Adobe InCopy CS6" set myMenuAction to menu action "$ID/Convert to Note" set myKeyStrings to find key strings for title of myMenuAction if class of myKeyStrings is list then repeat with myKeyString in myKeyStrings set myString to myKeyString & return end repeat else set myString to myKeyStrings end if display dialog(myString) end tell
注意 : ロケールに依存しない名前を取得する場合は、 menu
、 menu item
、 submenu
の名前を取得するよりも、 menu action
の名前を取得するほうが便利です。 menu action
のタイトルは、単一の文字列である場合が多い
からです。 その他のメニューオブジェクトの多くからは、 get key strings
メソッドで複数の文字列が返され
ます。
ロケールに依存しない名前を取得したら、スクリプトで使用することができます。 この文字列を使用したス
クリプトは、現在使用している InCopy と異なるロケールにインストールされている InCopy でも正常に機能
します。
ロケールに依存しない文字列を現在のロケールに変換するには、次のスクリプトを使用します(チュートリ
アルスクリプトの TranslateKeyString より)。 tell application "Adobe InCopy CS6" set myString to translate key string "$ID/Convert to Note" display dialog(myString) end tell
スクリプトからのメニューアクションの実行
InCopy に組み込まれている menu action
は、いずれもスクリプトから実行することができます。 menu action
が menu item
に割り当てられているとは限りませんが、その点を除けば、スクリプトから menu action
を実行することは、ユーザーインターフェイスでメニューオプションを選択することとまったく同じ
です。 例えば、あるメニューオプションを選択するとダイアログボックスが表示される場合、それに対応す
る menu action
をスクリプトから実行すると同じダイアログボックスが表示されます。
スクリプトから menu action
を実行する方法を、次のスクリプトに示します(完全なスクリプトについては、 tell application "Adobe InCopy CS6"
--Get a reference to a menu action.
set myMenuAction to menu action "$ID/Convert to Note"
--Run the menu action. The example action will fail if you do not
--have text selected.
invoke myMenuAction end tell
注意 : 一般的に、InCopy のプロセスをスクリプトで自動化する場合、メニューアクションやユーザーイン
ターフェイスを選択することで必要な処理を実行するのは、あまりよい方法とは言えません。InCopy のスク
リプトオブジェクトモデルを操作するほうが、はるかに確実で強力な処理を実現できます。 メニューアク
第 6 章 メニュー メニューやメニュー項目の追加 73
ションは、選択やウィンドウの状態など、ユーザーインターフェイスの様々な条件に依存しています。 オブ
ジェクトモデルを使用すれば、InCopy ドキュメント内のオブジェクトを直接操作できるので、ユーザーイン
ターフェイスに依存することなく、一貫性のある高速な処理を実現できます。
メニューやメニュー項目の追加
InCopy のユーザーインターフェイスと同じように、スクリプトでもメニューやメニュー項目の作成や削除が
法を、次のサンプルスクリプトに示します(完全なスクリプトについては、CustomizeMenu を参照してくだ
さい)。 tell application "Adobe InCopy CS6" set myMainMenu to menu "Main" set myTypeMenu to submenu "Type" of myMainMenu set myFontMenu to submenu "Font" of myTypeMenu set myKozukaMenu to submenu "Kozuka Mincho Pro " of myFontMenu tell myMainMenu set mySpecialFontMenu to make submenu with properties
{title:"Kozuka Mincho Pro"} end tell repeat with myMenuItem in menu items of myKozukaMenu set myAssociatedMenuAction to associated menu action of myMenuItem tell mySpecialFontMenu make menu item with properties
{associated menu action:myAssociatedMenuAction} end tell end repeat end tell
このスクリプトで追加したカスタムメニューを削除するには、RemoveSpecialFontMenu スクリプトを実行し
ます。 set myMainMenu to menu item "Main" set mySpecialFontMenu to submenu "Kozuka Mincho Pro" of myMainMenu tell mySpecialFontMenu to delete
メニューとイベント
ユーザーインターフェイスでメニューやサブメニューを選択すると、イベントが生成されます。これと同じ
ように、 menu action
や script menu action
スクリプトを使
用すれば、これらのイベントに応答するために event listener
を登録することができます。
スクリプティングコンポーネントのイベントを次の表に示します。
オブジェクト menu menu action
イベント beforeDisplay afterInvoke beforeInvoke
説明
メニューの内容が表示される前に、登録したスクリプトが実
行されます。
関連付けられている menu item
が選択されて、 onInvoke
イベン
トが発生した後に、登録したスクリプトが実行されます。
関連付けられている menu item
が選択されて、 onInvoke
イベン
トが発生する前に、登録したスクリプトが実行されます。
第 6 章 メニュー スクリプトメニューアクションの操作 74
オブジェクト script menu submenu action
イベント afterInvoke beforeInvoke beforeDisplay onInvoke beforeDisplay
説明
関連付けられている menu item
が選択されて、 onInvoke
イベン
トが発生した後に、登録したスクリプトが実行されます。
関連付けられている menu item
が選択されて、 onInvoke
イベン
トが発生する前に、登録したスクリプトが実行されます。 script menu action
の有効/チェックのステータスに対する内
部要求が行われる前に、登録したスクリプトが実行されます。 script menu action
が呼び出されたときに、登録したスクリプ
トが実行されます。 submenu
の内容が表示される前に、登録したスクリプトが実行
されます。 event
や event listener
を参照してください。
メニューに表示する項目を変更するには、 beforeDisplay event
に対する event listener
メ
ニューが選択されると、登録したスクリプト(メニュー項目の有効化/無効化や名前の変更などの、メ
ニューに関連するタスクを実行するスクリプト)が event listener
によって実行されます。
利用可能なフォント、最近使用したドキュメント、開いているウィンドウなどをメニューに表示するために、
内部的に使用されています。
スクリプトメニューアクションの操作
script menu action
を使用すると、 menu action
を新しく作成して、 onInvoke event
の発生時に指定のスクリ
プトを実行することができます。 script menu action
を作成してメニュー項目に割り当てる方法を、次のスクリプトに示します(完全なスク
リプトについては、MakeScriptMenuAction を参照してください)。 このスクリプトでは、メニュー項目が選択
されると、単に警告が表示されます。
第 6 章 メニュー スクリプトメニューアクションの操作 75 tell application "Adobe InCopy CS6"
--Create the script menu action "Display Message"
--if it does not already exist.
try set myScriptMenuAction to script menu action "Display Message" on error set myScriptMenuAction to make script menu action with properties {title:"Display Message"} end try tell myScriptMenuAction
--If the script menu action already existed,
--remove the existing event listeners.
if (count event listeners) > 0 then tell every event listener to delete end if set myEventListener to make event listener with properties
{event type:"onInvoke", handler:"yukino:message.applescript"} end tell tell menu "$ID/Main" set mySampleScriptMenu to make submenu with properties
{title:"Script Menu Action"} tell mySampleScriptMenu set mySampleScriptMenuItem to make menu item with properties
{associated menu action:myScriptMenuAction} end tell end tell end tell message.applescript
スクリプトファイルには、次のコードが含まれます。 tell application "Adobe InCopy CS6" display dialog ("You selected an example script menu action.") end tell
このスクリプトで作成した menu
、 submenu
、 menu item
、 script menu action
を削除するには、次のスクリプト
を実行します(チュートリアルスクリプトの RemoveScriptMenuAction より)。 tell application "Adobe InCopy CS6" try set myScriptMenuAction to script menu action "Display Message" tell myScriptMenuAction delete end tell tell submenu "Script Menu Action" of menu "$ID/Main" to delete end try end tell
すべての script menu action
を削除することもできます。次のスクリプトにその例を示します(チュートリ
アルスクリプトの RemoveAllScriptMenuActions より)。 このスクリプトでは、 script menu action
のメニュー
リストも削除されますが、作成したメニューやサブメニューは削除されません。 tell application "Adobe InCopy CS6" delete every script menu action end tell
現在のすべての script menu action
のリストを作成することができます。次のスクリプトにその例を示しま
す(チュートリアルスクリプトの GetScriptMenuActions より)。
第 6 章 メニュー スクリプトメニューアクションの操作 76 set myTextFile to choose file name {"Save Script Menu Action Names As"}
--If the user clicked the Cancel button, the result is null.
if myTextFile is not equal to "" then tell application "Adobe InCopy CS6" set myString to "" set myScriptMenuActionNames to name of every script menu action repeat with myScriptMenuActionName in myScriptMenuActionNames set myString to myString & myScriptMenuActionName & return end repeat my myWriteToFile(myString, myTextFile, false) end tell end if on myWriteToFile(myString, myFileName, myAppendData) set myTextFile to open for access myFileName with write permission if myAppendData is false then set eof of myTextFile to 0 end if write myString to myTextFile starting at eof close access myTextFile end myWriteToFile script menu action
を使用して、 beforeDisplay event
の発生時にスクリプトを実行することもできます。こ
の場合は、 script menu action
の状態に対する内部要求が行われる前に(メニュー項目が表示される直前に)
スクリプトが実行されます。 これは、スクリプトでメニュー名を変更したり、有効/チェックのステータス
を設定したりする場合に特に役立ちます。
次のサンプルスクリプトでは、 beforeDisplay event
に対する event listener
を追加して、現在の選択を確
認するようにしています。 何も選択されていない場合は、 event listener
のスクリプトによってメニュー項
目が無効化されます。 アイテムが選択されている場合は、メニュー項目が有効化されます。メニュー項目を
選択すると、選択されている最初のアイテムの種類が表示されます (完全なスクリプトについては、 tell application "Adobe InCopy CS6"
--Create the script menu action "Display Message"
--if it does not already exist.
try set myScriptMenuAction to script menu action "Display Message" on error set myScriptMenuAction to make script menu action with properties
{title:"Display Message"} end try tell myScriptMenuAction
--If the script menu action already existed,
--remove the existing event listeners.
if (count event listeners) > 0 then tell every event listener to delete end if
--Fill in a valid file path for your system.
第 6 章 メニュー スクリプトメニューアクションの操作 77 make event listener with properties {event type:"onInvoke", handler:"yukino:WhatIsSelected.applescript"} end tell tell menu "$ID/Main" set mySampleScriptMenu to make submenu with properties
{title:"Script Menu Action"} tell mySampleScriptMenu set mySampleScriptMenuItem to make menu item with properties
{associated menu action:myScriptMenuAction}
--Fill in a valid file path for your system.
make event listener with properties {event type:"beforeDisplay", handler:"yukino:BeforeDisplayHandler.applescript"} end tell end tell end tell
BeforeDisplayHander チュートリアルスクリプトファイルには、次のスクリプトが含まれます。 tell application "Adobe InCopy CS6" try set mySampleScriptAction to script menu action "Display Message" set mySelection to selection if (count mySelection) > 0 then set enabled of mySampleScriptAction to true else set enabled of mySampleScriptAction to false end if on error alert("Script menu action did not exist.") end try end tell
WhatIsSelected チュートリアルスクリプトファイルには、次のスクリプトが含まれます。 tell application "Adobe InCopy CS6" set mySelection to selection if (count mySelection) > 0 then set myString to class of item 1 of mySelection as string display dialog ("The first item in the selection is a " & myString & ".") end if end tell
7
イベント
章の更新ステータス
CS6
変更なし
InCopy スクリプティングでは、アプリケーションやドキュメントの一般的なイベント(ファイルのオープ
ン、新規ファイルの作成、印刷、ディスク上のテキストファイルやグラフィックファイルの読み込みなど)
に応答することができます。 アプリケーションで発生するイベントは、 event
オブジェクトによって表されま
す。 イベントにスクリプトを割り当てるには、 event listener
というスクリプトオブジェクトを使用します。
イベントに割り当てるスクリプトは、通常のスクリプトとほとんど同じですが、通常のスクリプトはユー
ザーが(スクリプトパネルから)実行するのに対して、イベントに割り当てるスクリプトは自動的に(目的
のイベントが発生したときに)実行される点が異なります。
この章では、InCopy のイベントを使用したスクリプトについて説明します。 最初は簡単なサンプルスクリプ
トから始めて、徐々に複雑なスクリプトへと進んでいきます。
ここでは、読者が
を既に読んでおり、スクリプトを作成、インストール、実行する方法
を理解しているものとして説明を行います。
この章では、アプリケーションやドキュメントに関連するイベントについて説明します。 メニューに関連す
を参照してください。
InCopy のイベントスクリプトモデルは、Worldwide Web Consortium(W3C)勧告のドキュメントオブジェク
トモデルイベントに似ています。 詳しくは、 http://www.w3c.org
を参照してください。
イベントスクリプトモデルについて
InCopy のイベントスクリプトモデルは、アプリケーションで発生する各種のイベントに相当する一連のオブ
ジェクトによって構成されています。 その中心となるのが event
オブジェクトです。これは、InCopy のユー
ザーインターフェイスで行われる特定のアクション(またはスクリプトの処理に相当するアクション)を表
します。
イベントに応答するには、そのイベントを受け取るオブジェクトに event listener
を登録します。
ジェクトが指定のイベントを受け取ると、 event listener
のハンドラー関数に定義されているスクリプト関
数(ディスク上のスクリプトファイルへの参照)が実行されます。
次の表に、 event listener
これらのイベントは、メニュー選択、キー
ボードショートカット、スクリプトアクションなどの任意の方法で発生させることができます。
78
第 7 章 イベント イベントスクリプトモデルについて 79
ユーザー
インターフェイス
イベント イベント名
任意のメニューア
クション beforeDisplay beforeDisplay
閉じる
書き出し
読み込み
新規
開く
プリント beforeInvoke afterInvoke onInvoke beforeClose afterClose beforeExport afterExport beforeImport afterImport beforeNew afterNew beforeOpen afterOpen beforePrint afterPrint
説明
メニューやサブメニューが表示される
前に発生。
スクリプトメニューアクションが表示
または変更される前に発生。
メニュー項目が選択された後、メ
ニューアクションの内容が実行される
前に発生。
メニューアクションが実行された後に
発生。
オブジェクトタイプ event event event event
メニューアクションやスクリプトメ
ニューアクションの実行時に発生。
「ドキュメントを閉じる」要求が発行
された後、ドキュメントが閉じられる
前に発生。 event document event
ドキュメントが閉じられた後に発生。 document event
書き出し要求が発行された後、ドキュ
メントまたはページアイテムが書き出
される前に発生。
ドキュメントまたはページアイテムが
書き出された後に発生。 import export event import export event
ファイルが読み込まれる前、ファイル
がドキュメントに読み込まれる前(配
置される前)に発生。
ファイルが読み込まれた後、ファイル
がページに配置される前に発生。
「新規ドキュメント」要求が発行され
た後、ドキュメントが作成される前に
発生。
新規ドキュメントが作成された後に発
生。 import export event import export event document event document event
「ドキュメントを開く」要求が発行さ
れた後、ドキュメントが開かれる前に
発生。
ドキュメントが開かれた後に発生。 document event document event document event 「ドキュメントのプリント」要求が発
行された後、ドキュメントがプリント
される前に発生。
ドキュメントがプリントされた後に発
生。 document event
第 7 章 イベント イベントスクリプトモデルについて 80
ユーザー
インターフェイス
イベント イベント名
復帰
保存
複製を保存
別名で保存 beforeRevert afterRevert beforeSave afterSave
説明
「ドキュメント復帰」要求が発行され
た後、保存されている以前の状態にド
キュメントが戻される前に発生。
保存されている以前の状態にドキュメ
ントが戻された後に発生。
オブジェクトタイプ document event document event
「ドキュメントの保存」要求が発行さ
れた後、ドキュメントが保存される前
に発生。 document event
ドキュメントが保存された後に発生。 document event beforeSaveACopy
「ドキュメントの複製保存」要求が発
行された後、ドキュメントが保存され
る前に発生。 afterSaveACopy document event
ドキュメントが保存された後に発生。 document event beforeSaveAs afterSaveAs
「ドキュメントの別名保存」要求が発
行された後、ドキュメントが保存され
る前に発生。 document event
ドキュメントが保存された後に発生。 document event
イベントプロパティとイベントの伝達について
ユーザーやスクリプトによってアクションが実行されてイベントが発生すると、そのイベントに応答可能な
スクリプティングオブジェクトにイベントが伝達されます。 特定のイベントに対する event listener
が登録
されているオブジェクトにそのイベントが伝達されると、その event listener
が呼び出されます。
ベントが複数のオブジェクトに伝達されて、複数のオブジェクトで処理が行われる場合もあります。
イベントの伝達には、次の 3 種類があります。
伝達しない — イベントターゲットに登録されている event listener
のみが呼び出されます。
イベントの例としては、 beforeDisplay
イベントがあります。
キャプチャ — スクリプトオブジェクトモデルの最上位(アプリケーション)から始まって、イベント
ターゲットまで伝達されます。 target
の上位にあるオブジェクトに登録されている、そのイベントに応
答可能なすべての event listener
でイベントが処理されます。
バブル — target
から伝達が開始されます。まず、 target
に登録されている応答可能な event listener
が呼び出されます。 次に、スクリプトオブジェクトモデルの上方向にイベントが伝達されます。スクリ
プトオブジェクトモデルで target
の上位にあるオブジェクトに登録されている、そのイベントに応答可
能な event listener
が呼び出されます。
次の表に、 event
のプロパティの詳細と、スクリプトオブジェクトモデルでのイベント伝達に与える影響を
示します。
第 7 章 イベント eventListener の操作 81
プロパティ
Bubbles
Cancelable
Captures
CurrentTarget
DefaultPrevented
EventPhase
EventType
PropagationStopped
Target
TimeStamp
説明 true の場合、 event
が発生したオブジェクトの上位にあるスクリプティングオブ
ジェクトにその event
が伝達されます。 true の場合、 target
における event
のデフォルトの動作をキャンセルできます。
これを行うには、 prevent default
コマンドを使用します。 true の場合、イベント伝達のキャプチャフェーズで、イベントのターゲットオブ
ジェクトの上位にあるスクリプティングオブジェクトに登録されている event listener
例えば、他の event listener
が呼び出される前に、アプリケーションの event listener
でドキュメントイベ
ントに応答することができます。 event
この表の
Target
を
参照してください。 true の場合、現在の target
(この表の
Target
を参照)における event
のデフォ
ルト動作が実行されず、アクションがキャンセルされます。 event
の伝達プロセスの現在のステージ。 event
のタイプを表す文字列( beforeNew true の場合、 current target
以降への伝達が中止されます(この表の
Target
を
参照してください)。 stop propagation
コマン
ドを使用します。 event
例えば、 beforeImport
イベントの
Target
はド
キュメントであり、 beforeNew
イベントの
Target
はアプリケーションです。 event
が発生した日時。
eventListener の操作
event listener
を作成するときには、イベントのタイプ(文字列)
イベントのキャプチャフェーズで event listener
を呼び出すかどうかを指定します。
て event listener
を追加する方法を、次のスクリプトに示します(完全なスクリプトについては、
--Registers an event listener on the afterNew event.
tell application "Adobe InCopy CS6" make event listener with properties {event type:"afterNew", handler:"yukino:ICEventHandlers:Message.applescript", captures:true} end tell
このスクリプトで参照されているスクリプトファイルには、次のコードが含まれています。 tell application "Adobe InCopy 3.0"
--"evt" is the event passed to this script by the event listener.
set myEvent to evt display dialog ("This event is the "& event type of myEvent & "event.") end tell
このスクリプトで作成した event listener
を削除するには、次のスクリプトを実行します(チュートリアル
スクリプトの RemoveEventListener より)。
第 7 章 イベント eventListener の操作 82 tell application "Adobe InCopy CS6" remove event listener event type "afterNew" handler file
"yukino:IDEventHandlers:Message.applescript" without captures end tell
1 つの event listener
でイベントが処理されても、そのイベントを監視している他の event listener
があれ afterOpen
イベントは、アプリケーションとドキュメントの両方の event listener
で監視されている可能性
があります。 event listener
は、現在の InCopy セッションを超えて保持されることはありません。
ションで event listener
を利用できるようにしたい場合は、スタートアップスクリプト用のフォルダーであ
る Startup Scripts にスクリプトを追加します(スクリプトのインストールについて詳しくは、 第 2 章「はじめ
を参照してください)。 event listener
スクリプトを追加しても、ドキュメントとともに
保存されたり、INX に書き出されたりすることはありません。
注意 : event listener
を定義するスクリプトで問題が発生した場合は、その event listener
を削除するスク
リプトを実行するか、InCopy を終了して再起動します。
スクリプトオブジェクトモデルの中で 1 つのイベントが伝達されて、複数の event listener
が呼び出される
場合があります。 次のサンプルスクリプトでは、様々なオブジェクトに登録されている event listener
が 1
つのイベントによって呼び出されます(完全なスクリプトについては、MultipleEventListeners を参照してく
--Shows that an event can trigger multiple event listeners.
tell application "Adobe InCopy CS6" set myDocument to make document
--You'll have to fill in a valid file path for your system make event listener with properties {event type:"beforeImport", handler:"yukino:EventInfo.applescript", captures:true} tell myDocument make event listener with properties {event type:"beforeImport", handler:"yukino:EventInfo.applescript", captures:true} end tell end tell
このスクリプトで参照されている
EventInfo.applescript
というスクリプトファイルには、次のスクリプト
コードが含まれています。 main(evt) on main(myEvent) tell application "Adobe InCopy CS6" set myString to "Current Target: " & name of current target of myEvent display dialog (myString) end tell end main
このスクリプトを実行してファイルを配置すると、ドキュメントの名前を示す警告と、アプリケーションの
名前を示す警告が順に表示されます。
次のサンプルスクリプトでは、サポートされている各イベントの event listener
を作成して、簡単なダイア
ログボックスにイベントに関する情報を表示しています。 完全なスクリプトについては、EventListenersOn を
参照してください。
第 7 章 イベント eventListener の操作 83
--Turns on all event listeners on the application object.
tell application "Adobe InCopy CS6" set myEventNames to {"beforeNew", "afterNew", "beforeQuit", "afterQuit", "beforeOpen",
"afterOpen", "beforeClose", "afterClose", "beforeSave", "afterSave", "beforeSaveAs",
"afterSaveAs", "beforeSaveACopy", "afterSaveACopy", "beforeRevert", "afterRevert", "beforePrint",
"afterPrint", "beforeExport", "afterExport", "beforeImport", "afterImport", "beforePlace",
"afterPlace"} repeat with myEventName in myEventNames make event listener with properties {event type:myEventName, handler:"yukino:GetEventInfo.applescript", captures:false} end repeat end tell
このスクリプトで参照されているスクリプトファイルには、次のコードが含まれています。 このファイル参
照で示されているディスク上の場所に、該当するスクリプトファイルが存在している必要があります。 完全
なスクリプトについては、
GetEventInfo.applescript
を参照してください。 main(evt) on main(myEvent) tell application "Adobe InCopy CS6" set myString to "Handling Event: " & event type of myEvent & return set myString to myString & "Target: " & name of target of myEvent & return set myString to myString & "Current: " & name of current target of myEvent & return set myString to myString & "Phase: " & my myGetPhaseName(event phase o f myEvent) & return set myString to myString & "Captures: " & captures of myEvent & return set myString to myString & "Bubbles: " & bubbles of myEvent & return set myString to myString & "Cancelable: " & cancelable of myEvent & return set myString to myString & "Stopped: " & propagation stopped of myEvent & return set myString to myString & "Canceled: " & default prevented of myEvent & return set myString to myString & "Time: " & time stamp of myEvent & return display dialog (myString) end tell end main
--Function returns a string corresponding to the event phase.
on myGetPhaseName(myEventPhase) tell application "Adobe InCopy CS6" if myEventPhase is at target then set myString to "At Target" else if myEventPhase is bubbling phase then set myString to "Bubbling" else if myEventPhase is capturing then set myString to "Capturing" else if myEventPhase is done then set myString to "Done" else if myEventPhase is not dispatching then set myString to "Not Dispatching" else set myString to "Unknown Phase" end if return myString end tell end myGetPhaseName
アプリケーションオブジェクトのすべての event listener
をオフにする方法を、次のサンプルスクリプトに
示します。 完全なスクリプトについては、EventListenersOff を参照してください。
第 7 章 イベント 「afterNew」eventListener の例 84
--EventListenersOff.applescript
--An InCopy CS6 AppleScript
--
--Turns off all of the event listeners on the application object.
tell application "Adobe InCopy CS6" tell event listeners to delete end tell
「afterNew」eventListener の例
afterNew
イベントは、ユーザー名、ドキュメントの作成日、著作権情報、その他の作業に関する情報などを
ドキュメントに追加したい場合に便利です。 ドキュメントのメタデータ(ファイル情報または XMP 情報とも
呼ばれます)にこのような情報を追加する方法を、次のサンプルスクリプトに示します。 完全なスクリプト
リストについては、AfterNew というチュートリアルスクリプトを参照してください。 tell application "Adobe InCopy CS6" make event listener with properties {event type:"afterNew", handler:"yukino:AfterNewHandler.applescript", captures:true} end tell
このスクリプトで参照されているスクリプトファイルには、次のコードが含まれています。 このファイル参
照で示されているディスク上の場所に、該当するスクリプトファイルが存在している必要があります。 完全
なスクリプトについては、
AfterNewHandler.applescript
を参照してください。
--AfterNewHandler.applescript
--An InCopy CS6 AppleScript
-main(evt) on main(myEvent) tell application "Adobe InCopy CS6" set user name to "Adobe" set myDocument to document 1 tell metadata preferences of myDocument set author to "Adobe Systems" set description to "This is an example document containing XMP metadata. Created: " & time stamp of myEvent end tell end tell end main
8
注釈
章の更新ステータス
CS6
変更なし
InDesign および InCopy では、インライン式の編集上の注釈機能を使用して、ストーリーのフローに影響を与
えることなく、注釈としてコメントを直接テキストに追加できます。 注釈機能は、ワークグループ環境で使
用する目的で設計されています。 特定の条件に基づいて、注釈に色を付けたり、オン / オフを切り替えたりす
ることもできます。
注釈を作成するには、ツールボックスの注釈ツール、注釈/新規注釈のコマンド、または注釈パレットの新
規注釈アイコンを使用します。
ここでは、読者が
を既に読んでおり、スクリプトを作成、インストール、実行する方法
を理解しているものとして説明を行います。 また、InCopy で注釈を操作する方法を理解しているものとして
います。
注釈の入力と読み込み
ここでは、InCopy ドキュメントに注釈を配置する方法について説明します。 InCopy のユーザーインターフェ
イスを使用して注釈を作成したり、注釈のテキストを置換したりするのと同じように、スクリプトを使用し
て注釈を作成したり、注釈にテキストを挿入したりすることができます。
ストーリーへの注釈の追加
ストーリーに注釈を追加するには、 add
メソッドを使用します。 次のサンプルでは、最後の挿入点に注釈を追
加しています。 完全なスクリプトについては、InsertNote を参照してください。 tell application "Adobe InCopy CS6" set myStory to story 1 of active document tell myStory
--Add note to a default story. We'll use the last insertion point in the story.
tell insertion point -1
--Add text to the note set myNote to make note set contents of text 1 of myNote to "This is a note." end tell end tell end tell
85
第 8 章 注釈 注釈からテキストへの変換およびテキストから注釈への変換 86
注釈のテキストの置換
注釈のテキストを置換するには、 contents
プロパティを使用します。次のサンプルにその例を示します。 完
全なスクリプトについては、Replace を参照してください。 tell application "Adobe InCopy CS6" set myStory to story 1 of active document set myNote to note 1 of myStory
-- We'll use the last insertion point in the story.
tell insertion point -1
--Add text to the note set contents of text 1 of myNote to "This is a note." end tell end tell
注釈からテキストへの変換およびテキストから注釈への変換
注釈からテキストへの変換
注釈をテキストに変換するには、 convert to text
メソッドを使用します。次のサンプルにその例を示しま tell application "Adobe InCopy CS6" set myStory to story 1 of active document set myNote to note 1 of myStory
--Convert the note to text tell myNote convert to text end tell end tell
テキストから注釈への変換
テキストを注釈に変換するには、 convert to note
メソッドを使用します。次のサンプルにその例を示しま tell application "Adobe InCopy CS6"
--Select a text set myStory to story 1 of active document select word 1 of myStory tell selection
-- Convert the text to a note set myWords to convert to note endtell end tell
第 8 章 注釈 注釈の展開と折りたたみ 87
注釈の展開と折りたたみ
注釈の折りたたみ
注釈を折りたたむ方法を、次のスクリプトに示します。 完全なスクリプトについては、CollapseNote を参照し
てください。 tell application "Adobe InCopy CS6" set myStory to story 1 of active document set myNote to note 1 of myStory
--Collapse a note set collapsed of myNote to true end tell
注釈の展開
注釈を展開する方法を、次のスクリプトに示します。 完全なスクリプトについては、ExpandNote を参照して
ください。 tell application "Adobe InCopy CS6" set myStory to story 1 of active document set myNote to note 1 of myStory
--Expand a note set collapsed of myNote to false end tell
注釈の削除
注釈を削除するには、 delete
メソッドを使用します。次のサンプルにその例を示します。 完全なスクリプト
については、RemoveNote を参照してください。 tell application "Adobe InCopy CS6" set myStory to story 1 of active document set myNote to note 1 of myStory
--Remove the note delete myNote end tell
注釈間の移動
ストーリー内の最初の注釈への移動
ストーリー内の最初の注釈に移動する方法を、次のスクリプトに示します。 完全なスクリプトについては、
FirstNote を参照してください。 tell application "Adobe InCopy CS6" set myStory to story 1 of active document set myNotes to notes of myStory set FirstNote to first item of myNote
--Add text to the first note set contents of text 1 of FirstNote to "This is the first note." end tell
第 8 章 注釈 注釈間の移動 88
ストーリー内の次の注釈への移動
ストーリー内の次の注釈に移動する方法を、次のスクリプトに示します。 完全なスクリプトについては、
NextNote を参照してください。 tell application "Adobe InCopy CS6" set myStory to story 1 of active document
-- current Note set myCount to 1 set myNote to note myCount of myStory set myCount to myCount + 1 set myNextNote to note 2 of myStory
--Add text to the next note set contents of text 1 of myNextNote to "This is the next note." end tell
ストーリー内の前の注釈への移動
ストーリー内の前の注釈に移動する方法を、次のスクリプトに示します。 完全なスクリプトについては、
PreviousNote を参照してください。 tell application "Adobe InCopy CS6" set myStory to story 1 of active document
-- current Note set myCount to 2 set myNote to note myCount of myStory
-- previous Note set myCount to myCount - 1 set myPrevNote to note myCount of myStory
--Add text to the previous note set contents of text 1 of myPrevNote to "This is the previous note." end tell
ストーリー内の最後の注釈への移動
ストーリー内の最後の注釈に移動する方法を、次のスクリプトに示します。 完全なスクリプトについては、
LastNote を参照してください。 tell application "Adobe InCopy CS6" set myStory to story 1 of active document set myNotes to notes of myStory set LastNote to last item of myNotes
--Add text to the last note set contents of text 1 of LastNote to "This is the last note." end tell
9
変更のトラック
章の更新ステータス
CS6
変更なし
原稿作成や編集作業の進行中に、ドキュメントの変更のトラック、表示/非表示、適用、取り消しを実行で
この章では、変更のトラックに関する一般的な操作をスクリプトで実行する方法について説明します。
ここでは、読者が
を既に読んでおり、スクリプトを作成、インストール、実行する方法
を理解しているものとして説明を行います。 また、InCopy でテキストを操作する方法や、組版に関する基本
的な用語を理解しているものとしています。
変更のトラック
ここでは、スクリプトを使用して、トラックされた変更に移動したり、変更を適用および取り消しする方法
について説明します。
既存のストーリーに含まれているテキストの追加や削除、移動が行われると、その変更がゲラビューおよび
ストーリービューに示されます。
トラックされた変更への移動
トラックされた変更の記録がストーリーに含まれている場合、ユーザーはトラックされた変更に順次移動す
ることができます。 トラックされた変更に移動する方法を、次のスクリプトに示します。
次のスクリプトでは、変更のインデックス番号を使用して、変更に対して繰り返し処理を行っています。 tell application "Adobe InCopy CS6" set myDocument to document 1 tell myDocument set myStory to story 1 tell myStory if (track changes) is true then set myChangeCounter to count set myChange to change 1 end if end tell end tell end tell
トラックされた変更の適用と取り消し
ストーリーに対する変更が行われた場合、変更のトラック機能を使用してすべての変更を見直したり、ス
トーリーにすべての変更を組み込むかどうかを決定できます。 ユーザーは、すべてのユーザーが行った変更
(テキストの追加や削除、移動)を適用および取り消しすることができます。
次のスクリプトでは、変更を適用します。
89
第 9 章 変更のトラック 変更のトラック 90 tell application "Adobe InCopy CS6" set myDocument to document 1 tell myDocument set myStory to story 1 tell myStory set myChange = myStory change 1 tell myChange accept end tell end tell end tell end tell
次のスクリプトでは、変更を取り消します。 tell application "Adobe InCopy CS6" set myDocument to document 1 tell myDocument set myStory to story 1 tell myStory set myChange = myStory change 1 tell myChange reject end tell end tell end tell end tell
トラックされた変更に関する情報
変更の情報には日付や時間などが含まれています。 次のスクリプトでは、トラックされた変更の情報を表示
します。
第 9 章 変更のトラック 変更のトラックの環境設定 91
--Shows how to get track change informations.
tell application "Adobe InCopy CS6" set myDocument to document 1 tell myDocument set myStory to story 1 tell myStory set myChange to change 1 tell myChange
-- change type (inserted text/deleted text/moved text, r/o) set myTypes to change type set myCharacters to characters set myDate to date set myInsertionPoints to insertion points set myLines to lines
-- paragraphs A collection of paragraphs.
set myParagraphs to paragraphs set myStoryOffset to story offset set myTextColumns to text columns set myTextStyleRanges to text style ranges set myTextsetiableInstances to text variable instances
-- The user who made the change. Note: Valid only when changes is true.
set myUserName to user name
-- Words A collection of words set myWords to words end tell end tell end tell end tell
変更のトラックの環境設定
変更のトラックの環境設定とは、変更のトラックに関するユーザー設定です。 例えば、トラックされる変更
の種類(テキストの追加や削除、移動)を定義できます。 トラックされた変更の種類別の外観を指定したり、
マージンの色付きの変更バーで変更を識別したりできます。 これらの環境設定を設定して取得する方法を、
次のスクリプトに示します。 tell application "Adobe InCopy CS6" set myTrackChangesPreference to track changes preferences tell myTrackChangesPreference
-- added background color choice (change background uses galley background color/change background uses user color/change background uses change pref color) : The background color option for added text.
set myAddedBackgroundColorChoice to added background color choice set added background color choice to change background uses change pref color
--added text color choice (change uses galley text color/change uses change pref color) :
The color option for added text.
set myAddedTextColorChoice to added text color choice set added text color choice to change uses change pref color
--background color for added text (any) : The background color for added text, specified as an InCopy UI color. Note: Valid only when added background color choice is change background uses change pref color. set myBackgroundColorForAddedText to background color for added text set background color for added text to gray
第 9 章 変更のトラック 変更のトラックの環境設定 92
--background color for deleted text (any) : The background color for deleted text, specified as an InCopy UI color. Note: Valid only when deleted background color choice is change background uses change pref color.
set myBackgroundColorForDeletedText to background color for deleted text set background color for deleted text to red
--background color for moved text (any) : The background color for moved text, specified as an InCopy UI color. Note: Valid only when moved background color choice is change background uses change pref color. set myBackgroundColorForMovedText to background color for moved text set background color for moved text to pink
--change bar color (any) : The change bar color, specified as an InCopy UI color. set myChangeBarColor to change bar color set change bar color to charcoal
--deleted background color choice (change background uses galley background color/change background uses user color/change background uses change pref color) : The background color option for deleted text.
set myDeletedBackgroundColorChoice to deleted background color choice set deleted background color choice to change background uses change pref color
--deleted text color choice (change uses galley text color/change uses change pref color) :
The color option for deleted text.
set myDeletedTextColorChoice to deleted text color choice set deleted text color choice to change uses change pref color
--location for change bar (left align/right align) : The change bar location.
set myLocationForChangeBar to location for change bar set location for change bar to left align
--marking for added text (none/strikethrough/underline single/outline) : The marking that identifies added text.
set myMarkingForAddedText to marking for added text set marking for added text to strikethrough
--marking for deleted text (none/strikethrough/underline single/outline) : The marking that identifies deleted text.
set myMarkingForDeletedText to marking for deleted text set marking for deleted text to underline single
--marking for moved text (none/strikethrough/underline single/outline) : The marking that identifies moved text.
set myMarkingForMovedText to marking for moved text set marking for moved text to outline
--moved background color choice (change background uses galley background color/change background uses user color/change background uses change pref color) : The background color option for moved text.
set myMovedBackgroundColorChoice to moved background color choice set moved background color choice to change background uses galley background color
-- moved text color choice (change uses galley text color/change uses change pref color) : The color option for moved text.
set myMovedTextColorChoice to moved text color choice set moved text color choice to change uses change pref color
-- If true, displays added text.
set myShowAddedText to show added text set show added text to true
第 9 章 変更のトラック 変更のトラックの環境設定 93
-- If true, displays change bars.
set myShowChangeBars to show change bars set show change bars to true
-- If true, displays deleted text.
set myShowDeletedText to show deleted text set show deleted text to true
-- If true, displays moved text.
set myShowMovedText to show moved text set show moved text to true
-- If true, includes deleted text when using the Spell Check command.
set mySpellCheckDeletedText to spell check deleted text set spell check deleted text to true
--The color for added text, specified as an InCopy UI color. Note: Valid only when added text color choice is change uses change pref color. set myTextColorForAddedText to text color for added text set text color for added text to blue
-- text color for deleted text (any) : The color for deleted text, specified as an InCopy
UI color. Note: Valid only when deleted text color choice is change uses change pref color. set myTextColorForDeletedText to text color for deleted text set text color for deleted text to yellow
-- The color for moved text, specified as an InCopy UI color. Note: Valid only when moved text color choice is change uses change pref color. set myTextColorForMovedText to text color for moved text set text color for moved text to green end tell end tell
10
アサイン
章の更新ステータス
CS6
変更なし
アサインは、InDesign ファイルに含まれるテキストやグラフィック用のコンテナで、InCopy で表示および編
集できます。 一般的に、アサインには、関連するテキストやグラフィックが含まれます(雑誌の記事を構成
このチュートリアルでは、アサインに関する一般的な操作をスクリプトで実行する方法について説明します。
ここでは、読者が
を既に読んでおり、スクリプトを作成、インストール、実行する方法
を理解しているものとして説明を行います。
アサインオブジェクト
この節では、アサインとアサインファイルを操作する方法について説明します。 スクリプトを使用して、ア
サインファイルを開いてアサインのプロパティを取得できます。
アサインファイルを開く
既存のアサインファイルを開く方法を、次のスクリプトに示します。 tell application "Adobe InCopy CS6" set myDesktopFolder to path to desktop as string set myFile to myDesktopFolder & "a.icma"
--Opens an existing document. You'll have to fill in your own file path
--in the variable "myFile".
set myDocument to open myFile tell myDocument set myAssignement to assignment 1 end tell end tell
アサインのプロパティに対する繰り返し処理
アサインのプロパティ(アサイン名、ユーザー名、アサインファイルの場所、アサインの書き出しオプショ
ンなど)を取得する方法を、次のスクリプトに示します。
94
第 10 章 アサイン アサインのストーリー 95 tell application "Adobe InCopy CS6" set myDocument to document 1 tell myDocument set myAssignement to assignment 1 tell myAssignement set myuserName to user name set myFilePath to file path set myDocPath to document path set myFramecolor to frame color set myincludeLinksWhenPackage to include links when package
-- Export options for assignment files.
-- ASSIGNED_SPREADS: Exports only spreads with assigned frames
-- EMPTY_FRAMES: Exports frames but does not export content
-- EVERYTHING: Exports the entire document.
set myExportOptions to export options end tell end tell end tell
アサインパッケージ
アサインパッケージ(InCopy で作成した .
incp
ファイル)は、アサインファイルが含まれた圧縮フォルダー
です。 createPackage
メソッドを使用すると、アサインをパッケージ化することができます。
クリプトでは、この方法でパッケージファイルを作成しています。 tell application "Adobe InDesign CS6" set myDocument to document 1 tell myDocument set myAssignement to assignment 1 tell myAssignement if packaged is false then set myDesktopFolder to path to desktop as string set myFile to myDesktopFolder & "b.icap" create package myFile with FORWARD_PACKAGE end if end tell end tell end tell
アサインのストーリー
次の図に、InCopy のアサインオブジェクトモデルを示します。 アサインドキュメントには、1 つ以上のアサ
インが含まれます。アサインには、アサインされたストーリーが含まれないか、または 1 つ以上のアサイン
されたストーリーが含まれます。 アサインされた各ストーリーは、テキストストーリーまたは画像ストー
リーを参照します。
第 10 章 アサイン アサインのストーリー 96
document
1
1…* assignment
1
0…* assigned story
1 text/image story
1
この節では、アサインされたストーリーとアサインストーリーのプロパティを取得する方法について説明し
ます。
アサインされたストーリーオブジェクト
アサインオブジェクトから、アサインされたストーリーを取得する方法を、次のスクリプトに示します。 tell application "Adobe InCopy CS6" set myDocument to document 1 tell myDocument set myAssignement to assignment 1 tell myAssignement set myAssignmentStory to assigned story 1 end tell end tell end tell
アサインされたストーリーのプロパティに対する繰り返し処理
オブジェクトのすべてのプロパティを取得する方法を、次のスクリプトに示します。 tell application "Adobe InCopy CS6" set myDocument to document 1 tell myDocument set myAssignement to assignment 1 tell myAssignement set myAssignmentStory to assigned story 1 tell myAssignmentStory set myName to name end tell end tell end tell set myFilePath to file path set myStoryReference to story reference end tell
11
XML
章の更新ステータス
CS6
変更なし
XML(Extensible Markup Language)は、World Wide Web Consortium( www.w3.org
)で作成と管理が行われて
いる、テキストベースのマークアップシステムです。 XML では、HTML(Hypertext Markup Language)と同じ
ように、不等号記号で囲まれたマークアップタグ(
<article>
や
<para>
など)が使用されます。
使用できるタグが事前に定義されていますが、XML では独自のタグを作成して、ドキュメントの構造をより
詳細に記述することができます。
高い柔軟性を備えている XML は、データの保存形式として広く利用されています。 InCopy には、XML データ
をページレイアウトに読み込むための様々な機能が用意されていますが、それらはスクリプトを使用して制
御できます。
ここでは、読者が
を既に読んでおり、スクリプトを作成、インストール、実行する方法
を理解しているものとして説明を行います。 また、XML、DTD、XSLT に関する基礎知識を持っていることを前
提としています。
概要
XML はフォーマットを行うためのものではなく、ドキュメントの構造を記述するためのものです。したがっ
て、ページレイアウト作業で XML を活用するには、やや複雑な手順が必要になります。 InCopy は、XML に完
全かつ柔軟に対応できますが、次のような制約があります。
によって表現された XML 要素は、元の XML 要素とは異なります。
い場合は、XML 要素そのものを複製する必要があります。
XML 要素のレイアウト上での出現順序は、XML 構造での出現順序とほぼ同じになります。
XML 要素に関連付けられているストーリー内のテキストは、その要素のデータになります。
InCopy での XML スクリプティングの推奨事項
XML ファイルの処理は、InCopy の外部で(InCopy のレイアウトに XML ファイルを読み込む前に)そのほと
んどを行うのが一般的です。 InCopy の外部では、XML エディターや XML パーサーなどの様々な便利なツール
が利用できます。
大規模な XML データ構造に含まれている要素を再配置したり複製したりする場合は、XSLT を使用して XML
を変換することを推奨します。 これは、XML ファイルを読み込むときに実行できます。
97
第 11 章 XML
XML 要素のスクリプティング 98
XML 要素のスクリプティング
ここでは、XML 環境設定や XML 読み込み環境設定の指定、XML の読み込み、XML 要素の作成、XML 属性の追
加を行う方法について説明します。 ここでは、XML コンテンツ自体を操作するスクリプトについて説明しま
す。XML 要素にフォーマットを適用するスクリプトについては、
XML 環境設定の指定
XML ビュー環境設定オブジェクトを使用して、InCopy の構造パネルの外観を制御できます。次のスクリプト
にその例を示します(チュートリアルスクリプトの XMLViewPreferences より)。 tell application "Adobe InCopy CS6" set myDocument to make document tell myDocument tell XML view preferences set show attributes to true set show structure to true set show tagged frames to true set show tag markers to true set show text snippets to true end tell end tell end tell
また、XML 環境設定オブジェクトを使用して、XML タグ付きプリセット環境設定(表やストーリーのデフォ
ルトのタグ名やユーザーインターフェイスカラー)を指定することもできます。次のスクリプトにその例を
示します(チュートリアルスクリプトの XMLPreferences より)。 tell application "Adobe InCopy CS6" set myDocument to make document tell myDocument tell XML preferences set default cell tag color to blue set default cell tag name to "cell" set default image tag color to brick red set default image tag name to "image" set default story tag color to charcoal set default story tag name to "text" set default table tag color to cute teal set default table tag name to "table" end tell end tell end tell
XML 読み込み環境設定の指定
XML ファイルを読み込む前に、XML 読み込み環境設定を指定することができます。この環境設定を使用すれ
ば、XSLT 変換を適用したり、XML ファイル内の空白文字の処理方法を制御したり、繰り返すテキスト要素を
作成したりすることができます。 XML 読み込み環境設定オブジェクトの設定方法を、次のスクリプトに示し
ます(チュートリアルスクリプトの XMLImportPreferences より)。
第 11 章 XML
XML 要素のスクリプティング 99 tell application "Adobe InCopy CS6" set myDocument to make document tell myDocument tell XML import preferences set allow transform to false set create link to XML to false set ignore unmatched incoming to true set ignore whitespace to true set import CALS tables to true set import style to merge import set import text into tables to false set import to selected to false set remove unmatched existing to false set repeat text elements to true
--The following properties are only used when the
--allow transform property is set to true.
--set transform filename to "yukino:myTransform.xsl"
--If you have defined parameters in your XSL file,
--you can pass them to the file during the XML import
--process. For each parameter, enter a list containign two
--strings. The first string is the name of the parameter,
--the second is the value of the parameter.
--set transform parameters to {{"format", "1"}} end tell end tell end tell
XML の読み込み
XML 読み込み環境設定を指定したら、XML ファイルを読み込みます。次のスクリプトにその例を示します
(チュートリアルスクリプトの ImportXML より)。 tell myDocument import XML from "yukino:completeDocument.xml" end tell
XML ファイルの内容を特定の XML 要素に読み込む必要がある場合は、ドキュメントではなく XML 要素の tell myDocument set myXMLTag to make xml tag with properties{name:"xml_element"} set myXMLElement to make XML elemement with properties{markup tag:myXMLTag]
--Import into the new XML element.
tell myXMLElement import from "yukino:completeDocument.xml" end tell end tell
または、 xml import preferences
オブジェクトの import to selected
プロパティを true に設定し、XML 要素
を選択した状態で XML ファイルを読み込む方法もあります。次のスクリプトにその例を示します(チュート
リアルスクリプトの ImportXMLIntoSelectedXMLElement より)。
第 11 章 XML
XML 要素のスクリプティング 100 tell myDocument set myXMLTag to make XML tag with properties{name: "xml_element"} tell XML element 1 set myXMLElement to make XML element with properties{markup tag: myXMLTag} end tell tell XML import preferences set import to selected to true end tell select myXMLElement import XML from "yukino:text.xml" end tell
XML タグの作成
の要素名が、ドキュメントの XML タグのリストに追加されます。 また、XML タグを直接作成することもでき
ます。次のスクリプトにその例を示します(チュートリアルスクリプトの MakeXMLTags より)。 tell application "Adobe InCopy CS6" set myDocument to make document tell myDocument
--You can create an XML tag without specifying a color for the tag.
set myXMLTagA to make XML tag with properties {name:"XML_tag_A"}
--You can define the highlight oclor o fthe XML tag.
set myXMLTagB to make XML tag with properties {name:"XML_tag_B", color:gray}
--...or you can proved an RGB array to set the color of the tag.
set myXMLTagC to make XML tag with properties {name:"XML_tag_C", color:{0, 92, 128}} end tell end tell
XML タグのロード
XML データを読み込む前にタグとスタイルのマッピングを行いたい場合に便利です。次のスクリプトにその
例を示します(チュートリアルスクリプトの LoadXMLTags より)。 tell myDocument load xml tags from "yukino:test.xml" end tell
XML タグの保存
ファイルから XML タグをロードするのとは逆に、XML タグをファイルに保存することもできます。 これを行
うと、タグだけが XML ファイルに保存されます。ドキュメントデータは保存されません。 この処理は、XML
を書き出すより高速で、生成されるファイルも小さくなります。 XML タグを保存する方法を、次のサンプル
スクリプトに示します(完全なスクリプトについては、SaveXMLTags を参照してください)。 save XML tags to "yukino:xml_tags.xml" version comments "Tag set created October 5, 2006"
第 11 章 XML
XML 要素のスクリプティング 101
XML 要素の作成
通常、XML 要素は XML ファイルを読み込んで作成しますが、InCopy スクリプティングを使用して XML 要素
を作成することもできます。次のスクリプトにその例を示します(チュートリアルスクリプトの tell myDocument set myXMLTag to make xml tag with properties{name:"myXMLTag"} set myRootElement to xml element 1 tell myRootElement set myXMLElement to make xml element with properties{markup tag:myXMLTag} end tell set contents of myXMLElement to "This is an XML element containing text." end tell
XML 要素の移動
move
メソッドを使用して、XML 構造内の XML 要素を移動できます。次のスクリプトにその例を示します
(チュートリアルスクリプトの MoveXMLElement より)。 tell application "Adobe InCopy CS6" set myDocument to make document tell myDocument set myXMLTag to make XML tag with properties {name:"myXMLTag"} set myRootElement to XML element 1 tell myRootElement set myXMLElementA to make XML element with properties
{markup tag:myXMLTag} set contents of myXMLElementA to "This is XML element A." set myXMLElementB to make XML element with properties
{markup tag:myXMLTag} set contents of myXMLElementB to "This is XML element B." end tell move myXMLElementA to after myXMLElementB
--Place the root XML element so that you can see the result.
tell story 1 place XML using myRootElement end tell end tell end tell
XML 要素の削除
XML 要素を削除すると、レイアウトと XML 構造の両方から XML 要素が削除されます。次のスクリプトにその
例を示します(チュートリアルスクリプトの DeleteXMLElement より)。 tell xml element 1 of myRootXMLElement to delete
XML 要素の複製
XML 要素を複製すると、新しい XML 要素が、XML 構造内の元の XML 要素の直後に追加されます。次のスク
リプトにその例を示します(チュートリアルスクリプトの DuplicateXMLElement より)。
第 11 章 XML
XML 要素のスクリプティング 102 tell application "Adobe InCopy CS6" set myDocument to make document tell myDocument set myXMLTag to make XML tag with properties {name:"myXMLTag"} set myRootElement to XML element 1 tell myRootElement set myXMLElementA to make XML element with properties
{markup tag:myXMLTag} set contents of myXMLElementA to "This is XML element A." set myXMLElementB to make XML element with properties
{markup tag:myXMLTag} set contents of myXMLElementB to "This is XML element B." end tell duplicate myXMLElementA
--Place the root XML element so that you can see the result.
tell story 1 place XML using myRootElement end tell end tell end tell
XML 構造からのアイテムの削除
XML 要素とテキストオブジェクトとの関連付けを削除するには、 untag
メソッドを使用します。次のスクリ
プトにその例を示します。 このメソッドを使用すると、XML 要素との関連付けは削除されますが、オブジェ
クトそのものは削除されません。 XML 要素が削除されたコンテンツは、親の XML 要素に関連付けられます。
XML 要素がルート XML 要素の場合、その XML 要素に関連付けられているレイアウトオブジェクト(テキスト
またはページアイテム)は、ドキュメントに保持されます (完全なスクリプトについては、UntagElement を
参照してください)。 tell XML element -2 to untag
XML コメントの作成
のスクリプトに示します(チュートリアルスクリプトの MakeXMLComment より)。 tell myRootXMLElement set myXMLElement to make XML element with properties{markup tag:myXMLTag} tell myXMLElement make xml comment with properties{contents:"This is an XML comment."} end tell end tell
XML 処理命令の作成
処理命令(PI:Processing Instruction)とは、XML ドキュメントを読み込むアプリケーションに対する命令が
含まれている XML 要素のことです。 XML 処理命令は、InCopy では無視されますが、他のアプリケーションで
使用するために InCopy の XML 構造に挿入することができます。 XML ドキュメントには複数の処理命令を含め
ることができます。
<?xml-stylesheet type="text/css" href="generic.css"?>
XML 処理命令を追加する方法を、次のスクリプトに示します(完全なスクリプトについては、
第 11 章 XML
XML 要素のスクリプティング 103 tell myRootXMLElement make xml processing instruction with properties{target:"xml-stylesheet type=¥"text/css¥".", data:"href=¥"generic.css¥""} end tell
XML 属性の操作
次のスクリプトに示します。 XML 要素には任意の数の XML 属性を追加できますが、各属性の名前はその要素
内で固有のものであることが必要です(例えば、「id」という名前の属性を 2 つ使用することはできません)。
XML 要素に XML 属性を追加する方法を、次のスクリプトに示します(完全なスクリプトについては、 tell application "Adobe InCopy CS6" set myDocument to make document tell myDocument set myXMLTag to make XML tag with properties {name:"myXMLElement"} set myRootXMLElement to XML element 1 tell myRootXMLElement set myXMLElement to make XML element with properties
{markup tag:myXMLTag} tell myXMLElement make XML attribute with properties {name:"example_attribute", value:"This is an XML attribute."} end tell end tell end tell end tell
スクリプトを使用して属性を直接作成する以外に、XML 要素を変換して属性を作成することもできます。 こ
れを行うと、XML 要素のテキスト内容が XML 属性の値として使用され、XML 要素の親に追加されます。 XML
要素の名前が属性の名前になるので、同じ名前を持つ属性が XML 要素の親に既に存在している場合は、作成
に失敗します。 XML 要素にページアイテムが含まれている場合、それらのページアイテムはレイアウトから
削除されます。
は、XML 属性の親の先頭または末尾に追加できます。 デフォルトでは、親要素の先頭に追加されます。
新しい XML 要素に XML マークアップタグを指定することもできます。 このパラメーターを省略すると、その
XML 属性が含まれている XML 要素と同じ XML タグを使用して新しい XML 要素が作成されます。
XML 要素を XML 属性に変換する方法を、次のスクリプトに示します(完全なスクリプトについては、 tell myDocument set myXMLTag to make XML tag with properties {name:"myXMLElement"} set myRootXMLElement to XML element 1 end tell tell myRootXMLElement set myXMLElement to make XML element with properties
{markup tag:myXMLTag, contents:"This is content in an XML element."} end tell tell myXMLElement convert to attribute end tell
第 11 章 XML ストーリーへの XML 要素の追加 104
XML 属性を XML 要素に変換することもできます。次のスクリプトにその例を示します(チュートリアルスク
リプトの ConvertAttributeToElement より)。 tell application "Adobe InCopy CS6" set myDocument to make document tell myDocument set myXMLTag to make XML tag with properties {name:"myXMLElement"} set myRootXMLElement to XML element 1 end tell tell myRootXMLElement set myXMLElementA to make XML element with properties
{markup tag:myXMLTag, contents:"A"} set myXMLElementB to make XML element with properties
{markup tag:myXMLTag, contents:"B"} set myXMLElementC to make XML element with properties
{markup tag:myXMLTag, contents:"C"} set myXMLElementD to make XML element with properties
{markup tag:myXMLTag, contents:"D"} end tell tell myXMLElementB set myAttribute to make XML attribute with properties
{name:"example_attribute", value:"This is an XML attribute."} end tell tell myAttribute convert to element located element end markup tag myXMLTag end tell end tell
XML ストーリーの操作
レイアウト要素(ストーリーまたはページアイテム)に関連付けられていない XML 要素を読み込むと、その
要素は XML ストーリーに格納されます。 テキストフレーム内のテキストと同じように、配置されていない
については、XMLStory を参照してください)。 set myXMLStory to xml story 1 of myDocument set the point size of text 1 of myXMLStory to 72
XML の書き出し
InCopy ドキュメントから XML を書き出す方法としては、ドキュメント内の XML 構造全体を書き出す方法と、
プトにその例を示します(完全なスクリプトについては、ExportXML を参照してください)。 export to "yukino:test.xml" format "XML"
ストーリーへの XML 要素の追加
これまでの節では、XML データを InCopy ドキュメントに読み込んで、ドキュメント内の XML 構造を操作す
る方法について説明しました。 この節では、XML 情報をストーリーに読み込んでフォーマットを行う方法に
ついて説明します。
第 11 章 XML ストーリーへの XML 要素の追加 105
XML 要素とテキストとの関連付け
テキストに既存の XML 要素を関連付けるには、 place xml
メソッドを使用します。
と、ページアイテムの内容が XML 要素の内容に置き換わります。次のスクリプトにその例を示します
(チュートリアルスクリプトの PlaceXML より)。 tell myDocument tell story 1 plac XML using myRootXMLElement end tell end tell
既存のテキストオブジェクトに既存の XML 要素を関連付けるには、 markup
メソッドを使用します。
ソッドを使用すると、テキストオブジェクトの内容と XML 要素の内容(存在する場合)が結合されます。 markup
メソッドを使用する方法を、次のスクリプトに示します(完全なスクリプトについては、Markup を
参照してください)。 tell application "Adobe InCopy CS6" set myDocument to make document tell myDocument set myXMLTag to make XML tag with properties {name:"myXMLElement"} set myRootXMLElement to XML element 1
--Place the XML root element so that you can see
--the result in the Structure panel.
tell story 1 place XML using myRootXMLElement set myString to "This is the first paragraph in the story.¥r" set myString to myString & "This is the second paragraph in the story.¥r" set myString to myString & "This is the third paragraph in the story.¥r" set myString to myString & "This is the fourth paragraph in the story.¥r" set contents to myString end tell tell myRootXMLElement set myXMLElement to make XML element with properties
{markup tag:myXMLTag} end tell tell paragraph 3 of story 1 markup using myXMLElement end tell end tell end tell
XML テキスト要素の内部や周囲へのテキストの挿入
や「住所」などのラベル)を XML 要素のテキストに追加したいことがあります。 XML 要素の内部や周囲にテ
キストを追加する方法を、次のサンプルスクリプトに示します(完全なスクリプトについては、
第 11 章 XML ストーリーへの XML 要素の追加 106 tell application "Adobe InCopy CS6" set myDocument to make document tell myDocument set myXMLTag to make XML tag with properties {name:"myXMLElement"} set myRootXMLElement to XML element 1 tell myRootXMLElement set myXMLElementA to make XML element with properties
{markup tag:myXMLTag} set contents of myXMLElementA to "This is a paragraph in an XML story." set myXMLElementB to make XML element with properties
{markup tag:myXMLTag} set contents of myXMLElementB to "This is a another paragraph in an XML story." set myXMLElementC to make XML element with properties
{markup tag:myXMLTag} set contents of myXMLElementC to "This is the third paragraph in an XML story." set myXMLElementD to make XML element with properties
{markup tag:myXMLTag} set contents of myXMLElementD to "This is the last paragraph in an XML story." tell myXMLElementA
--By inserting the return character after the XML element, the
--character becomes part of the content of the parent XML element,
--and not part of the content of the XML element itself.
insert text as content using return position after element end tell tell myXMLElementB insert text as content using "Static text: " position before element insert text as content using return position after element end tell tell myXMLElementC insert text as content using "Text at the start of an element: " position element start insert text as content using " Text at the end of an element. " position element end end tell tell myXMLElementD end tell end tell tell story 1 place XML using myRootXMLElement end tell end tell insert text as content using "Text before the element: " position before element insert text as content using " Text after the element. " position after element end tell
スタイルへのタグのマッピング
XML テキスト要素にフォーマットを適用する最も簡単な方法の 1 つが、 xml import maps
を使用してタグを
スタイルにマッピングする方法です。 この方法では、特定の XML タグを段落スタイルや文字スタイルに関連
付けることができます。 ドキュメントの map tags to styles
メソッドを使用すると、テキストにスタイルが
適用されます。次のスクリプトにその例を示します(チュートリアルスクリプトの MapTagsToStyles より)。
第 11 章 XML ストーリーへの XML 要素の追加 107 tell application "Adobe InCopy CS6" set myDocument to document 1 tell myDocument
--Create a tag to style mapping.
make XML import map with properties {markup tag:"heading_1", mapped style:"heading 1"} make XML import map with properties {markup tag:"heading_2", mapped style:"heading 2"} make XML import map with properties {markup tag:"para_1", mapped style:"para 1"} make XML import map with properties {markup tag:"body_text", mapped style:"body text"}
--Apply the xML tag to style mapping map XML tags to styles end tell
--Place the story so that you can see the result of the change.
tell story 1 of myDocument place XML using XML element 1 of myDocument end tell end tell
タグへのスタイルのマッピング
XML 要素が関連付けられていないフォーマットされたテキストを XML 構造に移動したい場合は、スタイルを
タグにマッピングします。これによって、段落スタイルや文字スタイルを XML タグに関連付けることができ
ます。 これを行うには、 xml export maps
オブジェクトを使用して、XML タグとスタイルの間にリンクを作成
し、 map styles to tags
メソッドを使用して該当する XML 要素を作成します。次のスクリプトにその例を示
します(チュートリアルスクリプトの MapStylesToTags より)。 tell application "Adobe InCopy CS6" set myDocument to document 1 tell myDocument
--Create a tag to style mapping.
make XML export map with properties {markup tag:"heading_1", mapped style:"heading 1"} make XML export map with properties {markup tag:"heading_2", mapped style:"heading 2"} make XML export map with properties {markup tag:"para_1", mapped style:"para 1"} make XML export map with properties {markup tag:"body_text", mapped style:"body text"}
--Apply the style to xml tag mapping.
map styles to XML tags end tell end tell
別の方法としては、単純に、ドキュメント内のすべての段落スタイルや文字スタイルに対して新しい XML タ
グを作成して、スタイルをタグにマッピングする方法があります。次のスクリプトにその例を示します
(チュートリアルスクリプトの MapAllStylesToTags より)。
第 11 章 XML ストーリーへの XML 要素の追加 108 tell application "Adobe InCopy CS6" set myDocument to document 1 tell myDocument
--Create a tag to style mapping.
repeat with myParagraphStyle in paragraph styles set myParagraphStyleName to name of myParagraphStyle set myXMLTagName to my myReplace(myParagraphStyleName, " ", "_") set myXMLTagName to my myReplace(myXMLTagName, "[", "") set myXMLTagName to my myReplace(myXMLTagName, "]", "") set myMarkupTag to make XML tag with properties {name:myXMLTagName} make XML export map with properties {markup tag:myMarkupTag, mapped style:myParagraphStyle} end repeat
--Apply the style to XML tag mapping.
map styles to XML tags end tell end tell
XML 要素へのスタイルの適用
タグとスタイルをマッピングしたり、XML 要素が関連付けられているテキストやページアイテムにスタイル
を適用したりする以外に、XML 要素にスタイルを直接適用することもできます。 apply paragraph style
およ
び apply character style
メソッドを使用する方法を、次のスクリプトに示します (完全なスクリプトにつ
いては、ApplyStylesToXMLElements を参照してください)。 tell application "Adobe InCopy CS6" set myDocument to make document tell myDocument set horizontal measurement units of view preferences to points set vertical measurement units of view preferences to points
--Create a series of XML tags.
set myHeading1XMLTag to make XML tag with properties {name:"heading_1"} set myHeading2XMLTag to make XML tag with properties {name:"heading_2"} set myPara1XMLTag to make XML tag with properties {name:"para_1"} set myBodyTextXMLTag to make XML tag with properties {name:"body_text"}
--Create a series of paragraph styles.
set myHeading1Style to make paragraph style with properties
{name:"heading 1", point size:24} set myHeading2Style to make paragraph style with properties
{name:"heading 2", point size:14, space before:12} set myPara1Style to make paragraph style with properties
{name:"para 1", point size:12, first line indent:0} set myBodyTextStyle to make paragraph style with properties
{name:"body text", point size:12, first line indent:24}
--Create a character style.
set myCharacterStyle to make character style with properties
{name:"Emphasis", font style:"Italic"}
--Add XML elements.
set myRootXMLElement to XML element 1 tell myRootXMLElement set myXMLElementA to make XML element with properties
{markup tag:myHeading1XMLTag, contents:"Heading 1"} tell myXMLElementA insert text as content using return position after element apply paragraph style using myHeading1Style clearing overrides yes end tell set myXMLElementB to make XML element with properties
{markup tag:myPara1XMLTag, contents:"This is the first paragraph in
第 11 章 XML ストーリーへの XML 要素の追加 109 the article."} tell myXMLElementB insert text as content using return position after element apply paragraph style using myPara1Style clearing overrides yes end tell set myXMLElementC to make XML element with properties
{markup tag:myBodyTextXMLTag, contents:"This is the second paragraph in the article."} tell myXMLElementC insert text as content using return position after element apply paragraph style using myBodyTextStyle clearing overrides yes end tell set myXMLElementD to make XML element with properties
{markup tag:myHeading2XMLTag, contents:"Heading 2"} tell myXMLElementD insert text as content using return position after element apply paragraph style using myHeading2Style clearing overrides yes end tell set myXMLElementE to make XML element with properties
{markup tag:myPara1XMLTag, contents:"This is the first paragraph following the subhead."} tell myXMLElementE insert text as content using return position after element apply paragraph style using myPara1Style clearing overrides yes end tell set myXMLElementF to make XML element with properties
{markup tag:myBodyTextXMLTag, contents:"Note:"} tell myXMLElementF insert text as content using " " position after element apply character style using myCharacterStyle end tell set myXMLElementG to make XML element with properties
{markup tag:myBodyTextXMLTag, contents:"This is the second paragraph following the subhead."} tell myXMLElementG insert text as content using return position after element apply paragraph style using myBodyTextStyle clearing overrides no end tell end tell end tell
--Place the story so that you can see the result of the change.
tell story 1 of myDocument place XML using myRootXMLElement end tell end tell
XML 表の操作
HTML 標準の表タグでデータがマークアップされている場合、InCopy はその XML データを自動的に表セルに
読み込みます。 デフォルトの表マークアップを使用できないか、使用を避けたい場合は、 convert element to table
メソッドを使用して XML 要素を表に変換できます。
このメソッドを使用するには、表に変換する XML 要素が特定の構造になっている必要があります。 表の各行
が特定の XML 要素に対応しており、その要素の中に、行内の各セルに対応する一連の XML 要素が含まれてい
る必要があります。 このメソッドを使用する方法を、次のスクリプトに示します(完全なスクリプトについ
ては、ConvertXMLElementToTable を参照してください)。 テーブル行を表すために使用されている XML 要素
は、このプロセスによって変換されます。
第 11 章 XML ストーリーへの XML 要素の追加 110 tell application "Adobe InCopy CS6" set myDocument to make document tell myDocument
--Create a series of XML tags.
set myRowTag to make XML tag with properties {name:"Row"} set myCellTag to make XML tag with properties {name:"Cell"} set myTableTag to make XML tag with properties {name:"Table"}
--Add XML elements.
set myRootXMLElement to XML element 1 tell myRootXMLElement set myTableXMLElement to make XML element with properties
{markup tag:myTableTag} tell myTableXMLElement repeat with myRowCounter from 1 to 6 set myXMLRow to make XML element with properties
{markup tag:myRowTag} tell myXMLRow set myString to "Row " & myRowCounter repeat with myCellCounter from 1 to 4 make XML element with properties {markup tag:myCellTag, contents:myString & ":Cell " & myCellCounter} end repeat end tell end repeat convert element to table row tag myRowTag cell tag myCellTag end tell end tell
--Place the story so that you can see the result of the change.
tell story 1 of myDocument place XML using XML element 1 of myDocument end tell end tell end tell
XML 要素で構成されている表では、XML 要素に関連付けられている表やセルにスタイルを適用するのではな
く、XML 要素に表スタイルやセルスタイルを直接適用することができます。 これを行うには、 applyTableStyle
メソッドや applyCellStyle
メソッドを使用します。次のスクリプトにその例を示します
(チュートリアルスクリプトの ApplyTableStyle より)。 tell application "Adobe InCopy CS6" set myDocument to make document tell myDocument
--Create a series of XML tags.
set myRowTag to make XML tag with properties {name:"Row"} set myCellTag to make XML tag with properties {name:"Cell"} set myTableTag to make XML tag with properties {name:"Table"}
--Create a table style and a cell style.
set myTableStyle to make table style with properties
{name:"myTableStyle", start row fill color:color "Black", start row fill tint:25, end row fill color:color "Black", end row fill tint:10} set myCellStyle to make cell style with properties
{name:"myCellStyle", fill color:color "Black", fill tint:45}
--Add XML elements.
set myRootXMLElement to XML element 1 tell myRootXMLElement set myTableXMLElement to make XML element with properties
{markup tag:myTableTag} tell myTableXMLElement repeat with myRowCounter from 1 to 6
第 11 章 XML ストーリーへの XML 要素の追加 111 set myXMLRow to make XML element with properties
{markup tag:myRowTag} tell myXMLRow set myString to "Row " & myRowCounter repeat with myCellCounter from 1 to 4 make XML element with properties {markup tag:myCellTag, contents:myString & ":Cell " & myCellCounter} end repeat end tell end repeat set myTable to convert element to table row tag myRowTag cell tag myCellTag end tell end tell set myTableXMLElement to XML element 1 of XML element 1 tell myTableXMLElement apply table style using myTableStyle with clearing overrides tell XML element 1 to apply cell style using myCellStyle tell XML element 4 to apply cell style using myCellStyle tell XML element 9 to apply cell style using myCellStyle tell XML element 14 to apply cell style using myCellStyle tell XML element 15 to apply cell style using myCellStyle tell XML element 20 to apply cell style using myCellStyle end tell end tell set alternating fills of myTable to alternating rows
--Place the story so that you can see the result of the change.
tell story 1 of myDocument place XML using XML element 1 of myDocument end tell end tell
Download
Advertisement
Key features
Text editing application
Collaborative workflow with InDesign
Track changes and add annotations
Fit copy to layout space
Identical typesetting results with InDesign
Frequently asked questions
InCopy CS6 is a collaborative text editing application designed to be used with Adobe InDesign. It is specifically designed for editors, writers, proofreaders, and others who work with copy in a publishing workflow.
InCopy CS6 is integrated with InDesign and uses the same text composition engine, ensuring identical typesetting results when copy is placed in the layout.
InCopy CS6 can track a variety of changes made to content, such as additions, deletions, and formatting modifications.
InCopy CS6 allows multiple users to work on the same content simultaneously, with each user's edits being tracked and reflected in the main InDesign layout.
No, InCopy CS6 is specifically for editing content that has already been placed in an InDesign layout.