InDesign 複数の文字を置換(ページ指定) AppleScript
2-3 03 特定のページのテキストフレーム内複数の文字を置換する(P.116)
- 作者: (株)シータス,古籏一浩
- 出版社/メーカー: 技術評論社
- 発売日: 2008/11/25
- メディア: 大型本
- 購入: 5人 クリック: 91回
- この商品を含むブログ (8件) を見る
=== 書籍の JavaScript を AppleScript で書き直してみます ===
部品作製
- 置換キーワードファイル[replace.txt]
- InDesign ドキュメント
- AppleScript ハンドラ
on replaceWords(myObj, repWords) -- 複数置換処理 on replaceWord(myObj, kw, rw) -- 置換処理 on split(myStr, mySep) -- 文字列を[mySep]で分割 -> リスト on join(myList, mySep) -- リストを[mySep]で連結 -> 文字列
上記ハンドラは、以下のエントリで実装済みです。
部品が揃ったので、まとめ
try set myFile to choose file with prompt "置換キーワードのファイルを指定してください" on error display dialog "置換キーワードファイルがありません。" error end try set myText to read (myFile) -- ファイル読み込み set repWords to every paragraph of myText -- 各行に分割 set targetPage to {1, 3} -- 置換対象ページ tell application "Adobe InDesign CS6" tell active document repeat with myPage in targetPage set fMax to number of every text frame of page myPage repeat with i from 1 to fMax set tfObj to text frame i of page myPage my replaceWords(tfObj, repWords) end repeat end repeat end tell end tell
実行結果
- OS X 10.8.5
- Adobe InDesign CS6, version: 8.0.2.413