下記はまず選択されたアイテムを調べる。アイテムはたとえ1つだけ選択していてもリストで返ってくるので、リスト内のアイテム分繰り返す。(それが1つめのrepeat)そこから選択オブジェクトのクラスがtext columnならテキストが選択されていると見て処理を続ける。
tell application "Adobe InDesign CS2_J"
tell document 1
--文字スタイルを変数CSに入れておく
set CS to character style "文字スタイル 1"
--選択オブジェクとを変数selectedItemListに入れる
set selectedItemList to selection
if selectedItemList is {} then --もしなければ
return --処理終了
end if --選択されたオブジェクトを調べる(listで返ってくる)
repeat with selectedItem in selectedItemList
--選択オブジェクト分繰り返す。
set myClass to class of selectedItem
--もし選択オブジェクトが文字列なら
if myClass is text column then
--文字数分繰り返す
repeat with C from 1 to count characters of selectedItem
--もし文字が "0123456789"の中のどれかなら
if contents of character C of selectedItem is in "0123456789" then
--文字スタイルをつける
set applied character style of character C of selectedItem to CS
end if
end repeat
end if
end repeat
end tell
end tell
選択オブジェクトのクラスはよく使うものとして
if myClass is rectangle then--画像ボックス等四角です。 if myClass is text farme then--テキストフレーム if myClass is text column then--テキスト if myClass is table then--表ほかにもわからないアイテムは page item で調べられます。ドキュメントの1ページ目に1つのオブジェクトを作り下記のようなスクリプトをつかうとクラスが何か調べる事が出来ます。
--ページアイテムのクラスを調べる時に使います。 tell application "Adobe InDesign CS2_J" tell page 1 of document 1 get class of page item 1 end tell end tell
コメントする