Archive for the 'InDesign CS3' Category

03/07 InDesign CS3で指定のオプジェクトを、JPEG書き出ししてiPhoneへ

InDesign CS3上で指定したオブジェクトをJPEG書き出ししてiPhoneに転送するAppleScriptです。

ことのはじまりは、目下開発中のiPhoneアプリ(私はプロジェクト管理やら仕様書書きやらを)で、Welcome画面の表示を行うのに「文字詰めや行送りをいろいろ指定できないと!」という話になったこと。

……そもそも、iPhoneの文字表示部品に、そんな気の利いたものはありません。そこで、InDesignやらIllustrator上で気の済むまで行間や文字間にこだわっていただいて、それをそのまま「画像」として書き出して表示しようではないか、と。

ただし、その指定内容をすぐにiPhoneの実機で見たいという話に。

その場で10分もかけずにInDesign書類上の指定レイヤー(「コンテンツ」)上に存在する指定名称(スクリプトラベル「screen」)のグループをJPEG書き出しして、書き出したJPEG書類をiPhotoにインポートして、iTunesに命令して接続しているすべてのiOSデバイスにシンクロを行うようAppleScriptで指令を出すようにしてみました。

できた瞬間はかなりガッツポーズでしたが、冷静に考えるとInDesignから書き出されるJPEG画像のクオリティが「残念なレベル」です。また、シンクロが終わるまでにちょっと時間がかかるので、実用性がいまひとつ。

結局、Good Reader for iPhoneをインストールして、iTunes経由でGood Readerに対してInDesignから書き出したPDFを渡す、という方法に落ち着きました。本Scriptは何らかの「可能性」を感じさせてくれはしたのですが、結局おクラ入りに。

スクリプト名:InDesign CS3で指定のオプジェクトを、JPEG書き出ししてiPhoneへ
–v1 InDesign CS3から直接JPEG書き出し。画像クオリティが低くて難あり

set dtPath to (path to desktop) as string
set fName to do shell script "date +%Y%m%d%H%M%S"

set fullPath to dtPath & fName & ".jpg"
set fullPathPOSIX to POSIX path of fullPath

tell application "Adobe InDesign CS3"
  tell document 1
    tell layer "コンテンツ"
      set aList to every group whose label is equal to "screen"
    end tell
    
    
set expItem to contents of first item of aList
    
export expItem format JPG to fullPath without with grids
    
  end tell
end tell

–iPhotoに書き出したJPEGファイルをインポートする
tell application "iPhoto"
  import from fullPathPOSIX
end tell

–アップデート可能なiOSデバイスをアップデートする
tell application "iTunes"
  repeat with i in sources
    if (kind of i is iPod) then update i
  end repeat
end tell

▼新規書類に ▼カーソル位置に ▼ドキュメント末尾に

07/18 InDesign CS3で選択中のオブジェクトの外周部の座標を取得する

InDesign CS3で選択中のオブジェクトの外周部の座標を取得するAppleScriptです。

idcs_range2.jpg

複数のオブジェクトの外周部の座標のみ取得したいという場合、安直にグループ化してその座標(geometric bouds)を取得する方法も考えないではないですが、元に戻すときに何かよくないこと(前後関係が狂うとか)が起こる可能性があるため、「グループ化→座標取得→グループ化解除」の順で処理するのは避けたいところ。

そこで、力ワザでありもののソートルーチンを用いて、ソートだけで取得するように処理してみました。y1とx1は昇順ソート、y2とx2は降順ソートして、それぞれ最初の項目から値を取得しています。

基礎的な属性アクセスしか使っていないため、とくにInDesignのバージョンに依存せずに使用できるはずです(tellブロックのアプリケーション名を書き換えるぐらい)。

スクリプト名:InDesign CS3で選択中のオブジェクトの外周部の座標を取得する
tell application “Adobe InDesign CS3″
  tell active document
    set gList to geometric bounds of selection
    
    
copy gList to y1List
    
copy gList to y2List
    
copy gList to x1List
    
copy gList to x2List
    
    
set y1Res to shellSortListAscending(y1List, 1) of me
    
set x1Res to shellSortListAscending(x1List, 2) of me
    
set y2Res to shellSortListDecending(y2List, 3) of me
    
set x2Res to shellSortListDecending(x2List, 4) of me
    
    
–外周部の座標を取得する
    
–y1, x1は最小のものを取得
    
set y1min to item 1 of item 1 of y1Res
    
set x1min to item 2 of item 1 of x1Res
    
    
–y2, x2は最大のものを取得
    
set y2max to item 3 of item 1 of y2Res
    
set x2max to item 4 of item 1 of x2Res
    
    
return {y1min, x1min, y2max, x2max}
    
–> {64.666666666667, 39.0, 177.0, 202.0}
  end tell
end tell

–シェルソートで入れ子のリストを昇順ソート
on shellSortListAscending(a, keyItem)
  set n to length of a
  
set cols to {1391376, 463792, 198768, 86961, 33936, 13776, 4592, 1968, 861, 336, 112, 48, 21, 7, 3, 1}
  
repeat with h in cols
    if (h (n - 1)) then
      repeat with i from h to (n - 1)
        set v to item (i + 1) of a
        
set j to i
        
repeat while (j h) and ((contents of item keyItem of item (j - h + 1) of a) > (item keyItem of v))
          set (item (j + 1) of a) to (item (j - h + 1) of a)
          
set j to j - h
        end repeat
        
set item (j + 1) of a to v
      end repeat
    end if
  end repeat
  
return a
end shellSortListAscending

–シェルソートで入れ子のリストを降順ソート
on shellSortListDecending(a, keyItem)
  set n to length of a
  
set cols to {1391376, 463792, 198768, 86961, 33936, 13776, 4592, 1968, 861, 336, 112, 48, 21, 7, 3, 1}
  
repeat with h in cols
    if (h (n - 1)) then
      repeat with i from h to (n - 1)
        set v to item (i + 1) of a
        
set j to i
        
repeat while (j h) and ((contents of item keyItem of item (j - h + 1) of a) < (item keyItem of v))
          set (item (j + 1) of a) to (item (j - h + 1) of a)
          
set j to j - h
        end repeat
        
set item (j + 1) of a to v
      end repeat
    end if
  end repeat
  
return a
end shellSortListDecending

▼新規書類に ▼カーソル位置に ▼ドキュメント末尾に

07/18 InDesign CS3で指定座標内に存在しているラインオブジェクトを抽出する

InDesign CS3で、指定座標内に重なっているラインオブジェクトを抽出するAppleScriptです。

とりあえず……画像を選択して本AppleScriptを実行すると、画像に重なっているラインオブジェクトを取り出してくれます。

引き出し線とその先の解説文字も含めて、プログラムの自動判別でひとかたまりに扱ってしまおうという目論見の課程で作られた試作品です。

画像を中心とした引き出し線+解説のテキストが入っているテキストフレームまでを1つの塊として認識して、外周部の座標を計算して、別途書き出しておいた画像をトリミングするという……図鑑などのやたらと画像点数が多いデータで「画像+解説部分」をひとまとめに取り出すためのプログラムに仕立て上げる予定(1日ぐらいでできそう)。

手作業部分をイレギュラーなものだけに限定できるので、圧倒的な効率化が実現できます。

idcs3_range.jpg

InDesign CS3用といっていますが、とくにそれほどバージョン依存しているわけではありません。書き換えもおそろしく簡単でしょう。

スクリプト名:InDesign CS3で指定座標内に存在しているラインオブジェクトを抽出する
tell application “Adobe InDesign CS3″
  tell document 1
    set aSel to first item of selection
    
set imgBounds to geometric bounds of aSel
    
    
set glList to every graphic line
    
set gvList to geometric bounds of every graphic line
    
    
set aRes to corruptRange_Y1X1Y2X2_retByID(imgBounds, gvList) of me
    
    
set selList to {}
    
repeat with i in aRes
      set the end of selList to item i of glList
    end repeat
    
    
  end tell
end tell

selList
–> {graphic line id 363 of page id 238 of spread id 233 of document “testdata.indd” of application “Adobe InDesign CS3″, graphic line id 267 of page id 238 of spread id 233 of document “testdata.indd” of application “Adobe InDesign CS3″, graphic line id 266 of page id 238 of spread id 233 of document “testdata.indd” of application “Adobe InDesign CS3″}

–指定矩形内に重なるデータをアイテム番号で返す
on corruptRange_Y1X1Y2X2_retByID(rangeList, targetList)
  set includedList to {}
  
  
set aCount to 1
  
  
set y1 to item 1 of rangeList
  
set x1 to item 2 of rangeList
  
set y2 to item 3 of rangeList
  
set x2 to item 4 of rangeList
  
  
repeat with i in targetList
    set targY1 to item 1 of i
    
set targX1 to item 2 of i
    
set targY2 to item 3 of i
    
set targX2 to item 4 of i
    
    
    
if ((x1 < targX1) and (targX1 < x2) and (y1 < targY1) and (targY1 < y2)) then
      set the end of includedList to aCount
    else if ((x1 < targX2) and (targX2 < x2) and (y1 < targY2) and (targY2 < y2)) then
      set the end of includedList to aCount
    end if
    
    
set aCount to aCount + 1
    
  end repeat
  
  
return includedList
end corruptRange_Y1X1Y2X2_retByID

▼新規書類に ▼カーソル位置に ▼ドキュメント末尾に

04/03 InDesign CS3でBookを作成するテスト

InDesign CS3で複数の書類をまとめた「Book」を作成するAppleScriptです。

別途、ノンブルを振っておく必要があるようです(作ったけど)。

スクリプト名:InDesign CS3でBookを作成するテスト
set myFileList to {}

set myFolder to choose folder

tell application “Finder”
  tell folder myFolder
    try
      –普通のケース
      
set fList to (every file whose name ends with “.indd”) as alias list
    on error
      –多分、ファイルが1つしか存在しなかったケース
      
set f2List to (every file whose name ends with “.indd”)
      
set fList to {}
      
repeat with i in f2List
        set the end of fList to i as alias
      end repeat
    end try
  end tell
end tell

if (count fList) > 0 then
  set myBookFile to choose file name with prompt “Save book file as”
  
  
tell application “Adobe InDesign CS3″
    set myBook to make new book with data {full name:myBookFile}
    
    
repeat with i in fList
      set j to contents of i
      
tell myBook
        make book content with data {full name:j}
      end tell
    end repeat
  end tell
  
else
  display dialog “No InDesign files were found in the selected folder.”
end if

▼新規書類に ▼カーソル位置に ▼ドキュメント末尾に

09/04 配置されたオブジェクトから取得した座標値を解析して、縦にいくつ並んでいるかを計算

InDeisgnのページアイテム(オブジェクト)から取得した座標値(geometric bounds)を解析して、それらが縦にいくつ並んでいるかを計算するAppleScriptです。

ind3.jpg

InDesignのドキュメント上に整然と並んでいるオブジェクトが、縦にいくつ並んでいるのかを計算します。

選択されたアイテム(selection)のうち、最初のものは左上のアイテムのはず(経験則から)なので、それを原点座標として定義します。

ind5.jpg

すべてのアイテムの座標値(geometric bounds)をY軸でソートして最大のものを検出。これで、一番左側の列の存在座標範囲を取得できます。

「整然と並んでいる」オブジェクトを処理対象としているため、配置精度が高いことが前提ですが……それでも配置座標には若干のゆらぎが発生している可能性もあるため、存在座標範囲をちょっとだけ外側にひろげて、ピックアップもれを起こす危険性を低減。

この範囲の中に存在する座標セットをサーチして、該当するものをピックアップ。個数を数えれば縦にいくつ並んでいるかを算出できます。

本AppleScriptでは、座標計算さえ行えればいいのでInDesignへのtellブロックは割愛しました。なお、InDesignなのでオブジェクトの座標はy1, x1, y2, x2という組み合わせです。

スクリプト名:配置されたオブジェクトから取得した座標値を解析して、縦にいくつ並んでいるかを計算
set aList to retGeometricBounds() of me

–(InDesign上の選択アイテムから取得した座標値のうち)リストの最初の項目は原点の座標だ、という経験則から
set originData to contents of first item of aList

set y1Max to contents of item 1 of first item of shellSortListDecending(aList, 1) of me –y1でソートして最大のものをリストアップ

(*

set y1Min to contents of item 1 of first item of shellSortListAscending(aList, 1) of me –y1でソートして最小のものをリストアップ

set x1Max to contents of item 2 of first item of shellSortListDecending(aList, 2) of me –x1でソートして最大のものをリストアップ
set x1Min to contents of item 2 of first item of shellSortListAscending(aList, 2) of me –x1でソートして最小のものをリストアップ

set y2Max to contents of item 3 of first item of shellSortListDecending(aList, 3) of me –y2でソートして最大のものをリストアップ
set y2Min to contents of item 3 of first item of shellSortListAscending(aList, 3) of me –y2でソートして最小のものをリストアップ

set x2Max to contents of item 4 of first item of shellSortListDecending(aList, 4) of me –x2でソートして最大のものをリストアップ
set x2Min to contents of item 4 of first item of shellSortListAscending(aList, 4) of me –x2でソートして最小のものをリストアップ
*)

set {origY1, origX1, origY2, origX2} to originData

set aGap to 2 –オブジェクトの配置ゆらぎに対して余裕をもって、大きめに検索エリア指定を行う
set areaList to {origY1 - aGap, origX1 - aGap, y1Max + (origY2 - origY1) + aGap, origX1 + origX2 + aGap}

set resList to withinRange_Y1X1Y2X2(areaList, aList) of me
set yItemNum to length of resList

–指定矩形内に含まれるデータをリストで返す
on withinRange_Y1X1Y2X2(rangeList, targetList)
  set includedList to {}
  
  
set y1 to item 1 of rangeList
  
set x1 to item 2 of rangeList
  
set y2 to item 3 of rangeList
  
set x2 to item 4 of rangeList
  
  
repeat with i in targetList
    set targY1 to item 1 of i
    
set targX1 to item 2 of i
    
set targY2 to item 3 of i
    
set targX2 to item 4 of i
    
    
if (x1 < targX1) and (x2 > targX2) and (y1 < targY1) and (y2 > targY2) then
      set the end of includedList to (contents of i)
    end if
  end repeat
  
  
return includedList
end withinRange_Y1X1Y2X2

–シェルソートで入れ子のリストを昇順ソート
on shellSortListAscending(a, keyItem)
  set n to length of a
  
set cols to {1391376, 463792, 198768, 86961, 33936, 13776, 4592, 1968, 861, 336, 112, 48, 21, 7, 3, 1}
  
repeat with h in cols
    if (h (n - 1)) then
      repeat with i from h to (n - 1)
        set v to item (i + 1) of a
        
set j to i
        
repeat while (j h) and ((contents of item keyItem of item (j - h + 1) of a) > (item keyItem of v))
          set (item (j + 1) of a) to (item (j - h + 1) of a)
          
set j to j - h
        end repeat
        
set item (j + 1) of a to v
      end repeat
    end if
  end repeat
  
return a
end shellSortListAscending

–シェルソートで入れ子のリストを降順ソート
on shellSortListDecending(a, keyItem)
  set n to length of a
  
set cols to {1391376, 463792, 198768, 86961, 33936, 13776, 4592, 1968, 861, 336, 112, 48, 21, 7, 3, 1}
  
repeat with h in cols
    if (h (n - 1)) then
      repeat with i from h to (n - 1)
        set v to item (i + 1) of a
        
set j to i
        
repeat while (j h) and ((contents of item keyItem of item (j - h + 1) of a) < (item keyItem of v))
          set (item (j + 1) of a) to (item (j - h + 1) of a)
          
set j to j - h
        end repeat
        
set item (j + 1) of a to v
      end repeat
    end if
  end repeat
  
return a
end shellSortListDecending

–テスト用データ。実際にはInDesignのDocument上の選択中のオブジェクトからgeometric boundsを取得した結果
on retGeometricBounds()
  return {{15.97, 6.0, 21.1, 10.0}, {21.1, 6.0, 26.23, 10.0}, {26.23, 6.0, 31.36, 10.0}, {31.36, 6.0, 36.49, 10.0}, {36.49, 6.0, 41.62, 10.0}, {41.62, 6.0, 46.75, 10.0}, {46.75, 6.0, 51.88, 10.0}, {51.88, 6.0, 57.01, 10.0}, {57.01, 6.0, 62.14, 10.0}, {62.14, 6.0, 67.27, 10.0}, {67.27, 6.0, 72.4, 10.0}, {72.4, 6.0, 77.53, 10.0}, {77.53, 6.0, 82.66, 10.0}, {82.66, 6.0, 87.79, 10.0}, {87.79, 6.0, 92.92, 10.0}, {92.92, 6.0, 98.05, 10.0}, {98.05, 6.0, 103.18, 10.0}, {103.18, 6.0, 108.31, 10.0}, {108.31, 6.0, 113.44, 10.0}, {113.44, 6.0, 118.57, 10.0}, {118.57, 6.0, 123.7, 10.0}, {123.7, 6.0, 128.83, 10.0}, {128.83, 6.0, 133.96, 10.0}, {133.96, 6.0, 139.09, 10.0}, {139.09, 6.0, 144.22, 10.0}, {144.22, 6.0, 149.35, 10.0}, {149.35, 6.0, 154.48, 10.0}, {154.48, 6.0, 159.61, 10.0}, {15.97, 24.35, 21.1, 28.35}, {21.1, 24.35, 26.23, 28.35}, {26.23, 24.35, 31.36, 28.35}, {31.36, 24.35, 36.49, 28.35}, {36.49, 24.35, 41.62, 28.35}, {41.62, 24.35, 46.75, 28.35}, {46.75, 24.35, 51.88, 28.35}, {51.88, 24.35, 57.01, 28.35}, {57.01, 24.35, 62.14, 28.35}, {62.14, 24.35, 67.27, 28.35}, {67.27, 24.35, 72.4, 28.35}, {72.4, 24.35, 77.53, 28.35}, {77.53, 24.35, 82.66, 28.35}, {82.66, 24.35, 87.79, 28.35}, {87.79, 24.35, 92.92, 28.35}, {92.92, 24.35, 98.05, 28.35}, {98.05, 24.35, 103.18, 28.35}, {103.18, 24.35, 108.31, 28.35}, {108.31, 24.35, 113.44, 28.35}, {113.44, 24.35, 118.57, 28.35}, {118.57, 24.35, 123.7, 28.35}, {123.7, 24.35, 128.83, 28.35}, {128.83, 24.35, 133.96, 28.35}, {133.96, 24.35, 139.09, 28.35}, {139.09, 24.35, 144.22, 28.35}, {144.22, 24.35, 149.35, 28.35}, {149.35, 24.35, 154.48, 28.35}, {154.48, 24.35, 159.61, 28.35}, {15.97, 42.7, 21.1, 46.7}, {21.1, 42.7, 26.23, 46.7}, {26.23, 42.7, 31.36, 46.7}, {31.36, 42.7, 36.49, 46.7}, {36.49, 42.7, 41.62, 46.7}, {41.62, 42.7, 46.75, 46.7}, {46.75, 42.7, 51.88, 46.7}, {51.88, 42.7, 57.01, 46.7}, {57.01, 42.7, 62.14, 46.7}, {62.14, 42.7, 67.27, 46.7}, {67.27, 42.7, 72.4, 46.7}, {72.4, 42.7, 77.53, 46.7}, {77.53, 42.7, 82.66, 46.7}, {82.66, 42.7, 87.79, 46.7}, {87.79, 42.7, 92.92, 46.7}, {92.92, 42.7, 98.05, 46.7}, {98.05, 42.7, 103.18, 46.7}, {103.18, 42.7, 108.31, 46.7}, {108.31, 42.7, 113.44, 46.7}, {113.44, 42.7, 118.57, 46.7}, {118.57, 42.7, 123.7, 46.7}, {123.7, 42.7, 128.83, 46.7}, {128.83, 42.7, 133.96, 46.7}, {133.96, 42.7, 139.09, 46.7}, {139.09, 42.7, 144.22, 46.7}, {144.22, 42.7, 149.35, 46.7}, {149.35, 42.7, 154.48, 46.7}, {154.48, 42.7, 159.61, 46.7}, {15.97, 61.05, 21.1, 65.05}, {21.1, 61.05, 26.23, 65.05}, {26.23, 61.05, 31.36, 65.05}, {31.36, 61.05, 36.49, 65.05}, {36.49, 61.05, 41.62, 65.05}, {41.62, 61.05, 46.75, 65.05}, {46.75, 61.05, 51.88, 65.05}, {51.88, 61.05, 57.01, 65.05}, {57.01, 61.05, 62.14, 65.05}, {62.14, 61.05, 67.27, 65.05}, {67.27, 61.05, 72.4, 65.05}, {72.4, 61.05, 77.53, 65.05}, {77.53, 61.05, 82.66, 65.05}, {82.66, 61.05, 87.79, 65.05}, {87.79, 61.05, 92.92, 65.05}, {92.92, 61.05, 98.05, 65.05}, {98.05, 61.05, 103.18, 65.05}, {103.18, 61.05, 108.31, 65.05}, {108.31, 61.05, 113.44, 65.05}, {113.44, 61.05, 118.57, 65.05}, {118.57, 61.05, 123.7, 65.05}, {123.7, 61.05, 128.83, 65.05}, {128.83, 61.05, 133.96, 65.05}, {133.96, 61.05, 139.09, 65.05}, {139.09, 61.05, 144.22, 65.05}, {144.22, 61.05, 149.35, 65.05}, {149.35, 61.05, 154.48, 65.05}, {154.48, 61.05, 159.61, 65.05}, {15.97, 79.4, 21.1, 83.4}, {21.1, 79.4, 26.23, 83.4}, {26.23, 79.4, 31.36, 83.4}, {31.36, 79.4, 36.49, 83.4}, {36.49, 79.4, 41.62, 83.4}, {41.62, 79.4, 46.75, 83.4}, {46.75, 79.4, 51.88, 83.4}, {51.88, 79.4, 57.01, 83.4}, {57.01, 79.4, 62.14, 83.4}, {62.14, 79.4, 67.27, 83.4}, {67.27, 79.4, 72.4, 83.4}, {72.4, 79.4, 77.53, 83.4}, {77.53, 79.4, 82.66, 83.4}, {82.66, 79.4, 87.79, 83.4}, {87.79, 79.4, 92.92, 83.4}, {92.92, 79.4, 98.05, 83.4}, {98.05, 79.4, 103.18, 83.4}, {103.18, 79.4, 108.31, 83.4}, {108.31, 79.4, 113.44, 83.4}, {113.44, 79.4, 118.57, 83.4}, {118.57, 79.4, 123.7, 83.4}, {123.7, 79.4, 128.83, 83.4}, {128.83, 79.4, 133.96, 83.4}, {133.96, 79.4, 139.09, 83.4}, {139.09, 79.4, 144.22, 83.4}, {144.22, 79.4, 149.35, 83.4}, {149.35, 79.4, 154.48, 83.4}, {154.48, 79.4, 159.61, 83.4}, {15.97, 97.75, 21.1, 101.75}, {21.1, 97.75, 26.23, 101.75}, {26.23, 97.75, 31.36, 101.75}, {31.36, 97.75, 36.49, 101.75}, {36.49, 97.75, 41.62, 101.75}, {41.62, 97.75, 46.75, 101.75}, {46.75, 97.75, 51.88, 101.75}, {51.88, 97.75, 57.01, 101.75}, {57.01, 97.75, 62.14, 101.75}, {62.14, 97.75, 67.27, 101.75}, {67.27, 97.75, 72.4, 101.75}, {72.4, 97.75, 77.53, 101.75}, {77.53, 97.75, 82.66, 101.75}, {82.66, 97.75, 87.79, 101.75}, {87.79, 97.75, 92.92, 101.75}, {92.92, 97.75, 98.05, 101.75}, {98.05, 97.75, 103.18, 101.75}, {103.18, 97.75, 108.31, 101.75}, {108.31, 97.75, 113.44, 101.75}, {113.44, 97.75, 118.57, 101.75}, {118.57, 97.75, 123.7, 101.75}, {123.7, 97.75, 128.83, 101.75}, {128.83, 97.75, 133.96, 101.75}, {133.96, 97.75, 139.09, 101.75}, {139.09, 97.75, 144.22, 101.75}, {144.22, 97.75, 149.35, 101.75}, {149.35, 97.75, 154.48, 101.75}, {154.48, 97.75, 159.61, 101.75}}
end retGeometricBounds

▼新規書類に ▼カーソル位置に ▼ドキュメント末尾に

07/31 InDesign CS3で、指定ScriptLabelの中のテキストの、指定行の指定文字以降を行末まで取得

InDesign CS3で、現在オープン中の最前面のドキュメント上の指定のScript Labelがついているtext frame中のテキストで、指定行目の指定文字以降の文字を行末まで取得するAppleScriptです。

「指定文字」が存在しなかった場合には行ごと返します。

id1.jpg

スクリプト名:InDesign CS3で、指定ScriptLabelの中のテキストの、指定行の指定文字以降を行末まで取得
set aRes to getLabeledDataAndPickUp("hiyokoMaker", 2, "/") of me
–> "ボボ・ブラジル"

set aRes to getLabeledDataAndPickUp("hiyokoMaker", 2, "ぴよぴよ") of me
–> "■ひよこの原産地/ボボ・ブラジル"

–指定ScriptLabelの中のテキストの、指定行の指定文字以降を行末まで取得
on getLabeledDataAndPickUp(aScriptLabel, aLineNum, aMarker)
  set aRes to retLabeledData(aScriptLabel) of me
  
set aList to paragraphs of aRes
  
set aLine to contents of item aLineNum of aList
  
set aPos to offset of aMarker in aLine
  
set aText to text (aPos + 1) thru -1 of aLine
  
return aText
end getLabeledDataAndPickUp

–指定のScript Labelのデータ(Contents)を取り出す
on retLabeledData(aScriptLabel)
  tell application "Adobe InDesign CS3"
    tell document 1
      try
        set aObj to every page item whose label is aScriptLabel
        
        
set targObj to first item of aObj
        
set aRes to contents of text 1 of targObj
      on error
        return "<error>"
      end try
    end tell
  end tell
end retLabeledData

▼新規書類に ▼カーソル位置に ▼ドキュメント末尾に

07/31 現在のドキュメント上のアイテムをすべてグループ解除

InDesign CS3で、現在オープン中の最前面のドキュメント上のオブジェクトをすべてグループ解除するAppleScriptです。

スクリプト名:現在のドキュメント上のアイテムをすべてグループ解除
ungroupAll() of me

on ungroupAll()
  tell application "Adobe InDesign CS3"
    tell document 1
      tell every page
        repeat
          set gList to every group
          
if gList = {} then exit repeat
          
tell every group to ungroup
        end repeat
      end tell
    end tell
  end tell
end ungroupAll

▼新規書類に ▼カーソル位置に ▼ドキュメント末尾に

11/06 InDesign CS3のuser interaction levelを取得、設定する

InDesign CS3で、エラーレベルの取得および設定を行うAppleScriptです。

InDesignでは、エラー時にどのレベルまで警告するか……というよりは、自動処理時にエラーを無視するために、user interaction levelを設定できます。たいていは、すべてのワーニングを無視する「never interact」に設定。すべての処理が終わったあとで、Script実行前に取得しておいた現在のワーニングレベルに戻す、という処理を行います。

スクリプト名:InDesign CS3のuser interaction levelを取得、設定する
set aRes to retUserInteractionLevel() of me
setUserInteractionLevel(0) of me

–InDesign CS3のuser interaction levelを設定する
on setUserInteractionLevel(aNum)
  if (aNum > -1) and (aNum < 3) then
    try
      using terms from application “Adobe InDesign CS3″
        tell application “Adobe InDesign CS3″
          tell script preference 1
            if aNum = 0 then
              set user interaction level to never interact
            else if aNum = 1 then
              set user interaction level to interact with all
            else if aNum = interact with alerts then
              set user interaction level to interact with all
            end if
          end tell
        end tell
      end using terms from
    end try
  else
    
  end if
end setUserInteractionLevel

–InDesign CS3のuser interaction levelを取得する
on retUserInteractionLevel()
  using terms from application “Adobe InDesign CS3″
    tell application “Adobe InDesign CS3″
      tell script preference 1
        set uRes to user interaction level
        
if uRes = never interact then
          –エラーやワーニングがあっても警告しない
          
return 0
        else if uRes = interact with all then
          –すべてのエラーやワーニングを警告する
          
return 1
        else if uRes = interact with alerts then
          –ワーニングについてのみ表示する
          
return 2
        end if
      end tell
    end tell
  end using terms from
end retUserInteractionLevel

▼新規書類に ▼カーソル位置に ▼ドキュメント末尾に