スクスニップ

AppleScriptの断片をここに書く

InDesign 段落の先頭の文字が「■」ならスタイルを適用 AppleScript

2-4 04 選択された段落の先頭の文字が「■」ならスタイルを適用する(P.124)

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

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

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

部品作製

f:id:mikomaya:20141113154618p:plain

f:id:mikomaya:20141113154629p:plain

-- 各段落の先頭が「■」なら段落スタイルを適用
to applyParagraphStyle(myObj, checkMark)
    tell application "Adobe InDesign CS6"
        
        -- 段落スタイルを変数に保存
        set pStyle to paragraph style "段落見出し" of document 1
        
        tell myObj
            -- 行数分繰り返す
            set loop to number of every paragraph
            repeat with i from 1 to loop
                
                -- 行頭文字 = ■?
                set myChar to first character of paragraph i
                if myChar is checkMark then
                    -- << javascript >> .applyParagraphStyle(pStyle)
                    apply paragraph style paragraph i using pStyle
                end if
                
            end repeat
        end tell
    end tell
end applyParagraphStyle

段落スタイル、文字スタイル、swatchなどの情報はそれぞれのファイルで保持しているので、 … of document 1 という記述になります。(of document 1 を削除して実行するとエラーに落ちます)

部品が揃ったので、実行

on run {}
    my setUp()
    my main()
    my tearDown()
end run

on setUp()
    tell document 1 of application "Adobe InDesign CS6"
        select every text frame of page 1
    end tell
end setUp

on main()
    set checkMark to "■"
    
    tell document 1 of application "Adobe InDesign CS6"
        set myList to selection -- 選択されたオブジェクトを変数に保存
        set loop to number of every item of myList
        repeat with i from 1 to loop
            set myTF to item i of myList
            applyParagraphStyle(myTF, checkMark) of me
        end repeat
    end tell
end main

on tearDown()
    activate
    display dialog "Script 終了" giving up after 3
end tearDown

実行結果

f:id:mikomaya:20141113154639p:plain