スクスニップ

AppleScriptの断片をここに書く

InDesign 複数の文字を置換(ページ指定) AppleScript

2-3 03 特定のページのテキストフレーム内複数の文字を置換する(P.116)

組版時間を半減する! InDesign自動処理実例集

組版時間を半減する! InDesign自動処理実例集

=== 書籍の JavaScriptAppleScript で書き直してみます ===

部品作製

  • 置換キーワードファイル[replace.txt]

f:id:mikomaya:20141112111058p:plain

f:id:mikomaya:20141112111117p:plain

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

実行結果

f:id:mikomaya:20141112113711p:plain