ごんれのラボ

iOS、Android、Adobe系ソフトの自動化スクリプトのことを書き連ねています。

InDesignで抜き出したテキストをFMPに流す

InDesignでAppleScript with FileMaker。

AppleScriptだと他のアプリケーションと連携できるからいいね。

この程度のスクリプトなら世に溢れてそうだったけど、

見つからなかったのでアップしてみます。

InDesignで選択しているテキストフレームからテキストを抜き出し、

ついでに段落スタイル名を取得して、それぞれに該当するからFMPのフィールドに、

抜き出したテキストを流し込むScript。

ついでに画像が配置されているグラフィックフレームの画像名を抜き出して、

指定の文言をFMPのフィールドに流し込むようにしてます。

まずは例をご覧あれ。


1.下記のようなInDesignオブジェクトを作成する

 (段落スタイル名もちゃんと当ててください)

 ピクチャ 1

2.下記のようなFMPを作成する

ピクチャ 2

4.InDesign上で抜き出したいテキストフレーム及びグラフィックフレームを選択する

5.FMPの流し込みたいレコードを表示しておく

6.スクリプトを実行すると各フィールドにテキストが流れます


<注意点>

●InDesign上でなにも選択していないとなにも起きません(当然)

●最前面のFMPの表示されているFMPを上書きして流し込みます

 (念のためバックアップをとっておかないとひどい目にあう予感がします)

●例ぐらいのテキスト量ならコピペしたほうが早いです

 ただ腱鞘炎にはならなくて済むと思います

(*

InDesignで抜き出したテキストをFMPに流す

制作日:2010.06.07

制作者:こうちゃん犬猫まみれ

*)

set s_text to ASCII character (13) --split用の区切り文字代入

tell application "Adobe InDesign CS3"

activate

tell document 1

set selObj to selection

repeat with i in selection

if class of i is rectangle then

try --画像が貼られていないものを対象外にする(エラーが出るかどうかで判別)

if (name of item link of graphic 1 of i) is "hoge.ai" then --配置された画像名で処理を変える

set MyText to "アイテム1"

set fieldName to "コラム種類"

my Filemaker_past(fieldName, MyText)

set MyText to "2"

set fieldName to "コラム番号"

my Filemaker_past(fieldName, MyText)

else if (name of item link of graphic 1 of i) is "hogehoge.ai" then

set MyText to "アイテム2"

set fieldName to "コラム種類"

my Filemaker_past(fieldName, MyText)

set MyText to "1"

set fieldName to "コラム番号"

my Filemaker_past(fieldName, MyText)

end if

end try

end if

if class of i is text frame then

try --「スタイルなし」を回避

set MyText to contents of text of i

set MyText to MyText as string --string変換しないとダメみたい

if MyText is "" then

set contents of text of i to " "

end if

set p_name to (name of applied paragraph style of paragraph 1 of text of i) as string --段落スタイル名を変数に入れる

on error --「スタイルなし」なら繰り返しを抜ける

return

end try

set MyText to contents of text of i

if p_name as string is "タイトル欧文" then

set MyText to MyText as string

my textSplit(s_text, MyText)

set theList to result

set fieldName to "欧文" --ハンドラ用にFMPのフィールド名を変数に代入

set MyText to item 1 of theList

my Filemaker_past(fieldName, MyText)

set fieldName to "和文"

set MyText to item 2 of theList

my Filemaker_past(fieldName, MyText)

else if p_name as string is "キャッチ" then

set MyText to MyText as string

set fieldName to "キャッチ"

my Filemaker_past(fieldName, MyText)

end if

--end try

end if

end repeat

end tell

display dialog "終了しました"

end tell

on textSplit(s_text, MyText) --splitするハンドラ

set tmp to AppleScript's text item delimiters --tmpに本来の区切り文字を格納

set AppleScript's text item delimiters to s_text --s_textが区切り文字

set theList to every text item of MyText --MyTextが処理したい文字列、theListが処理後のリスト

set AppleScript's text item delimiters to tmp --元に戻す

return theList --リストをメインスクリプトに返す

end textSplit

on Filemaker_past(fieldName, MyText)

tell application "FileMaker Pro"

tell document 1

tell current record --いま開いているレコードを対象にする

set cell fieldName to MyText --fieldNameフィールドにMyText(テキスト)を流す

end tell

end tell

end tell

end Filemaker_past