InDesignCS3で2つのオブジェクトの位置とサイズを合わせます。
付属の画像を見ていただけるとわかりやすいと思います。
チラシなどの部分角判処理用に作りました。
回転していたらだめです。
配置画像を背面に合わす.jsx
配置画像を前面に合わす.jsx
たぶん他のバーションのInDesignでも動くと思います。
ダウンロードはこちらbubun.zip
InDesign13

global textFlameList set myRec to the clipboard set textFlameList to {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} set OriginalDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to {tab} set myRec to text items of myRec tell application "Adobe Illustrator" tell document 1 set mySele to selection repeat with selObj in mySele my getTextFrameIndex(selObj) end repeat repeat with N from 1 to count myRec my NAGASIKOMI(item N of textFlameList, item N of myRec) end repeat end tell end tell set AppleScript's text item delimiters to OriginalDelimiters on getTextFrameIndex(selObj) tell application "Adobe Illustrator" if class of selObj is group item then set myCount to count page items of selObj repeat with N from 1 to myCount my getTextFrameIndex(page item N of selObj) end repeat else if class of selObj is text frame then set myName to name of selObj set itemNum to my getItemNum(myName) if itemNum > 0 then set item itemNum of textFlameList to selObj end if end if end tell end getTextFrameIndex on getItemNum(myName) return offset of myName in "ABCDEFGHIJKLMNOPQRSTUVWXYZ" end getItemNum on NAGASIKOMI(targetTextFrame, inputStr) if targetTextFrame is 0 then return end if tell application "Adobe Illustrator" set contents of targetTextFrame to inputStr if kind of targetTextFrame is area text then if my overflow(targetTextFrame) is true then set mySCL to horizontal scale of paragraph 1 of targetTextFrame my choutai(targetTextFrame, mySCL) end if end if end tell end NAGASIKOMI on choutai(targetTextFrame, mySCL) set mySCL to mySCL - 3 tell application "Adobe Illustrator" set horizontal scale of paragraph 1 of targetTextFrame to mySCL end tell if my overflow(targetTextFrame) is true then my choutai(targetTextFrame, mySCL) end if end choutai on overflow(tFrame) set OriginalDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to "" tell application "Adobe Illustrator" set myLastP to (contents of every paragraph of tFrame) as string set myLastL to (contents of every line of tFrame) as string set AppleScript's text item delimiters to OriginalDelimiters if myLastP is not myLastL then set AppleScript's text item delimiters to OriginalDelimiters return true else set AppleScript's text item delimiters to OriginalDelimiters return false end if end tell end overflow
tell application "Adobe InDesign CS2_J" tell document 1 get properties of hyperlink 1 --★ここから下でテキストをクリックしてページへのリンクを作成できる set theDest to make hyperlink page destination with properties ¬ {destination page:page 3, view setting:fit window} set myhyperlink to make hyperlink text source with properties ¬ {source text:text from character 1 to character -2 of paragraph 2 of ¬ text frame 1 of page 1} make hyperlink with properties {border color:black, highlight:invert, ¬ border style:solid, hidden:false, destination:theDest, ¬ source:myhyperlink, name:"456789", visible:false, width:thin} end tell end tell
tell application "Adobe InDesign CS2_J" tell document 1 --★ここから下でページへのリンクの親メニューを作成できる set theDest to make hyperlink page destination with properties ¬ {destination page:page 5, view setting:fit window} set oyaBookMark to make bookmark with properties ¬ {destination:theDest, name:"567"} --★ここから下でページへのリンクを作成できる set theDest to make hyperlink page destination with properties ¬ {destination page:page 5, view setting:fit window} make bookmark at end of oyaBookMark with properties ¬ {destination:theDest, name:"5"} --★ここから下でページへのリンクを作成できる set theDest to make hyperlink page destination with properties ¬ {destination page:page 6, view setting:fit window} make bookmark at end of oyaBookMark with properties ¬ {destination:theDest, name:"6"} --★ここから下でページへのリンクを作成できる set theDest to make hyperlink page destination with properties ¬ {destination page:page 7, view setting:fit window} make bookmark at end of oyaBookMark with properties ¬ {destination:theDest, name:"7"} end tell end tell
set ANS to display dialog "値段を入力してください。" default answer "1000" set plusNum to text returned of ANS set plusNum to my replaceAll(plusNum, "円", "") set plusNum to my replaceAll(plusNum, ",", "") set plusNum to plusNum as integer set OriginalDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to {""} tell application "Adobe InDesign CS2_J" tell active document tell selection set cellCount to count cells repeat with N from 1 to cellCount set myData to contents of cell N set myData to my replaceAll(myData, "円", "") set myData to my replaceAll(myData, ",", "") set myData to myData as integer set myData to myData + plusNum set myData to myData as string if length of myData = 4 then set myData to (character 1 of myData & "," & ¬ characters 2 thru 4 of myData & "円") as string else if length of myData = 5 then set myData to (characters 1 thru 2 of myData & "," & ¬ characters 3 thru 5 of myData & "円") as string else if length of myData = 6 then set myData to (characters 1 thru 3 of myData & "," & ¬ characters 4 thru 6 of myData & "円") as string end if set contents of cell N to myData end repeat end tell end tell end tell set AppleScript's text item delimiters to OriginalDelimiters on replaceAll(motoStr, findStr, repStr) set OriginalDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to {findStr} set motoStr to text items of motoStr set AppleScript's text item delimiters to {repStr} set motoStr to motoStr as string set AppleScript's text item delimiters to OriginalDelimiters return motoStr end replaceAll
tell application "Adobe InDesign CS2_J" tell document 1 tell text frame 1 make row of table 1 set rowCount to count rows of table 1 end tell end tell end tell
tell application "Adobe InDesign CS2_J" tell document 1 set PS to paragraph style "本文囲み内" set newTable to convert to table selection column separator "☆" ¬ row separator "☆" --行区切り列区切りを(ありえなさそうな文字)"☆"にしています。 set applied paragraph style of paragraphs 1 thru -1 of ¬ cell 1 of newTable to PS set bottom edge stroke weight of cell 1 of newTable to 0.1 set right edge stroke weight of cell 1 of newTable to 0.1 set left edge stroke weight of cell 1 of newTable to 0.1 set top edge stroke weight of cell 1 of newTable to 0.1 set bottom inset of cell 1 of newTable to 3.25 set top inset of cell 1 of newTable to 3.25 set left inset of cell 1 of newTable to 0 set right inset of cell 1 of newTable to 0 set width of cell 1 of newTable to 130 end tell end tell
tell application "Adobe InDesign CS2_J" activate set mySele to class of selection --選択されたアイテムが if mySele is cell or mySele is table then --もしセルかテーブルなら set selecount to count cells of selection --セルの数を数える repeat with C from 1 to selecount --セルの数分くりかえす if overflows of cell C of selection then --セルのテキストがあふれていたら repeat with myPer from 100 to 30 by -2 --100%から30%まで2%刻みで set horizontal scale of every paragraph of cell C of ¬ selection to myPer --長体をかけていく recompose cell C of selection if not overflows of cell C of selection then --セルのテキストが収まったら exit repeat --くりかえしを抜ける end if end repeat end if end repeat else display dialog "表を選択してください" end if end tell※09/04/17 長体が30%になるということでInDesignがアクティブになっていないとだめなのでactivateを入れました。でもまだ誤差が出るようです。overflowのチェックに時差が出ているようです。なので、ちょっと変更してみました。下記は段落1と行1を比べて同じかどうかチェックします。こっちのほうが確実ですが、複数行だと失敗しますのでご注意下さい。
tell application "Adobe InDesign CS2_J" activate set mySele to class of selection --選択されたアイテムが if mySele is cell or mySele is table then --もしセルかテーブルなら set selecount to count cells of selection --セルの数を数える repeat with C from 1 to selecount --セルの数分くりかえす if overflows of cell C of selection then --セルのテキストがあふれていたら set mypara to paragraph 1 of cell C of selection repeat with myPer from 100 to 30 by -2 --100%から30%まで2%刻みで set horizontal scale of every paragraph of cell C of ¬ selection to myPer --長体をかけていく --if not overflows of cell C of selection then set myline to line 1 of cell C of selection if not my getoverflow(mypara, myline) then --セルのテキストが収まったら exit repeat --くりかえしを抜ける end if end repeat end if end repeat else display dialog "表を選択してください" end if end tell on getoverflow(mypara, myline) if mypara = myline then return false else return true end if end getoverflow
set OriginalDelimiters to AppleScript's text item delimiters set myWaight to "0.0 mm" tell application "Adobe InDesign CS2_J" tell document 1 set selectedItems to selection if selectedItems is {} then return end if set selItem to item 1 of selectedItems set startCell to name of selItem set AppleScript's text item delimiters to {":"} set startCell to text items of startCell set startX to item 1 of startCell set startY to item 2 of startCell set indRowCount to count rows of selItem set indColumnCount to count columns of selItem --set left edge stroke weight of column (startX) of selItem to myWaight --set right edge stroke weight of ¬ column (startX + indColumnCount - 1) of selItem to myWaight set bottom edge stroke weight of row (startY + indRowCount - 1) of selItem¬ to myWaight end tell end tell set AppleScript's text item delimiters to OriginalDelimiters
tell application "Adobe InDesign CS2_J" --選択した表のcell 1は表全体の何行目か調べる set myRow to index of parent row of cell 1 of selection as integer --選択した表のcell 1の名前を調べる("1:3")とかで返ってくる get name of cell 2 of selection end tell
set myTable to the clipboard set OriginalDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to {return} set myTable to text items of myTable set AppleScript's text item delimiters to {tab} set myTable to myTable as string set myTable to text items of myTable set AppleScript's text item delimiters to OriginalDelimiters tell application "InDesign CS_J" set contents of selection to myTable --表組の内容を入れ替える。 end tell
tell application "Adobe InDesign CS2_J" tell document 1 tell text frame 1 set contents to "竹内 亨" set ruby flag of character 1 to yes set ruby string of character 1 to "たけ" set ruby flag of character 2 to yes set ruby string of character 2 to "うち" set ruby flag of character 4 to yes set ruby string of character 4 to "とおる" end tell end tell end tell
my test("L01spec", "TAKEUCHI:作業中:temp:tempL01.txt") on test {myLabel, FilePath} set myLabel to myLabel as string set FilePath to FilePath as string tell application "Adobe InDesign CS2_J" tell text frame myLabel of document 1 tell text 1 place FilePath end tell end tell end tell return "true" end run
set findList to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"} set findListCount to count findList tell application "Adobe InDesign CS2_J" tell document 1 set selectedItems to selection if selectedItems is {} then display dialog "テキストフレームを選択ツール(黒矢印)で¬ 選択してください。" return end if repeat with selItem in selectedItems if class of selItem is not text frame then display dialog "テキストフレームを選択ツール(黒矢印)で¬ 選択してください。" return else set Pnum to count paragraphs of selItem repeat with P from 1 to Pnum set myPara to paragraph P of selItem set FLG to false repeat with FL from 1 to findListCount if item FL of findList is in myPara then set FLG to true exit repeat end if end repeat if FLG is true then set Cnum to count characters of paragraph P of selItem repeat with N from 1 to Cnum if N = 1 then set TXTpre to "★" else set TXTpre to contents of character (N - 1) of ¬ paragraph P of selItem end if set TXT to contents of character N of paragraph P of selItem if N = Cnum then set TXTaf to "★" else set TXTaf to contents of character (N + 1) of ¬ paragraph P of selItem end if if TXTpre is in "01234567890123456789,." and ¬ TXT is in "01234567890123456789,." then set glyph form of character (N - 1) of paragraph P of ¬ selItem to monospaced half width form --等幅半角字形 set glyph form of character N of paragraph P of ¬ selItem to monospaced half width form --等幅半角字形 else if TXTpre is not in "01234567890123456789"¬ and TXT is in "01234567890123456789" ¬ and TXTaf is not in "01234567890123456789" then set properties of character N of paragraph P ¬ of selItem to {glyph form:monospaced half width form,¬ trailing aki:0.25, leading aki:0.25} end if end repeat end if end repeat end if end repeat end tell end tell display dialog "終了しました"
tell application "Adobe InDesign CS2_J" tell document 1 --最小3文字 set ANS to display dialog "何字取りを何字取りにしますか?¬ " default answer "9/7" buttons {"OK"} set myStr to text returned of ANS set motoJIDORI to 9 set newJidori to 7 set motoJIDORI to my nthFields(myStr, "/", 1) set newJidori to my nthFields(myStr, "/", 2) set selectedItems to selection if selectedItems is {} then return end if set selItem to item 1 of selectedItems tell selItem set jidori of every character whose jidori is motoJIDORI to newJidori end tell end tell end tell on nthFields(myStr, sep, num) set OriginalDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to {sep} set myStr to text items of myStr set AppleScript's text item delimiters to OriginalDelimiters return item num of myStr end nthFields
tell application "Adobe InDesign CS2_J" tell document 1 --最小3文字 set ANS to display dialog "何字取りを何字取りにしますか?¬ " default answer "9/7" buttons {"OK"} set myStr to text returned of ANS set motoJIDORI to 9 set newJidori to 7 set motoJIDORI to my nthFields(myStr, "/", 1) set newJidori to my nthFields(myStr, "/", 2) set selectedItems to selection if selectedItems is {} then return end if set selItem to item 1 of selectedItems tell selItem set jidori of every character whose jidori is motoJIDORI to newJidori end tell end tell end tell on nthFields(myStr, sep, num) set OriginalDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to {sep} set myStr to text items of myStr set AppleScript's text item delimiters to OriginalDelimiters return item num of myStr end nthFields
tell application "Adobe InDesign CS2_J" tell document 1 tell character style "英語" set applied font to "Times New Roman PS MT" set point size to "6 Q" end tell end tell end tell
tell application "Adobe InDesign CS2_J" tell active document set CS1 to character style "文字スタイル 1" tell text frame 1 of page 1 set applied character style of characters 1 thru 2 to CS1 end tell end tell end tell
tell application "Adobe InDesign CS2_J" set oldFindPreferences to properties of find preferences set oldChangePreferences to properties of change preferences tell active document tell page 1 my setPstyle(text frame 1, "■^9.", "■見出") end tell end tell set properties of find preferences to oldFindPreferences set properties of change preferences to oldChangePreferences end tell on setPstyle(TF serchString, styleName) tell application "Adobe InDesign CS2_J" set find preferences to nothing set change preferences to nothing tell active document set PS1 to paragraph style styleName search TF with find attributes {find text:serchString} ¬ with change attributes {applied paragraph style:PS1} end tell end tell end setPstyle
tell application "Adobe InDesign CS2_J" set oldFindPreferences to properties of find preferences --検索設定を変数oldFindPreferencesに入れておく set oldChangePreferences to properties of change preferences --置換設定を変数oldFindPreferencesに入れておく tell active document tell page 1 my FindRep1(text frame 1, "(1)", "<2474>") --オリジナル関数を呼び出す end tell end tell set properties of find preferences to oldFindPreferences --検索設定を元に戻す set properties of change preferences to oldChangePreferences --置換設定を元に戻す end tell on FindRep1(TF, findStr, repStr) tell application "Adobe InDesign CS2_J" set find preferences to nothing --検索設定をなしにする。 set change preferences to nothing --置換設定をなしにする。 tell active document search TF for findStr replacing with repStr end tell end tell end FindRep1
tell application "Adobe InDesign CS2_J" tell document 1 set PageCount to count pages repeat with N from 0 to PageCount - 1 set P to PageCount - N tell page P set Tcount to count text frames --テキストフレームの数を数える repeat with T from 1 to Tcount set myB to visible bounds of text frame T set W to (item 4 of myB) - (item 2 of myB) set H to (item 3 of myB) - (item 1 of myB) --テキストフレームの大きさを調べて if 113 < W and 162 < H then --大きければ本文のテキストフレームとする。 set myCha to character -1 of text frame T --最後の文字を取り出す。 set character -1 of text frame 1 to myCha & "<改頁>" --最後の文字を最後の文字+<改頁>にする。 end if end repeat end tell end repeat end tell end tell
tell application "Adobe InDesign CS2_J" tell document 1 set selectedItems to selection if selectedItems is {} then return end if set selItem to item 1 of selectedItems set myPer to 97 --まずスタートパーセントを97にする。 repeat --繰り返し set pStr to every paragraph of selItem as string --段落のテキストを取り出す set Lstr to line 1 of selItem as string --ライン(みかけの行)のテキストを取り出す if pStr is not Lstr then--もし段落と見かけの行が違うなら --変倍をかける set horizontal scale of paragraph 1 of selItem to myPer --パーセントから3を引いておく set myPer to myPer - 3 else--段落と見かけの行が同じなら exit repeat--繰り返しを抜ける end if end repeat end tell end tell
tell application "Adobe InDesign CS2_J" tell active document set PS to paragraph style "ノンブル" set countPage to count pages repeat with N from 1 to countPage tell page N set myStr to my HanToZen((N) as string) --ページ番号をオリジナル関数HanToZenを使って全角にする。 set Tobj to make text frames at beginning with properties ¬ {contents:myStr, visible bounds:¬ {297 - 15, 210 / 2 - 20, 297 - 10 + 5, 210 / 2 + 20}} --テキストフレームを作成し文字を入れる set applied paragraph style of paragraph 1 of Tobj to PS --スタイルを当てる。 end tell end repeat end tell end tell --オリシナル関数HanToZen on HanToZen(myStr) set findList to {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"} --半角文字リストを作成 set repList to {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"} --全角文字リストを作成 repeat with N from 1 to count findList set myStr to my FindAndRep(item N of findList, item N of repList, myStr) --リスト分検索置換 end repeat return myStr end HanToZen --オリシナル関数FindAndRep(検索置換) on FindAndRep(findStr, repStr, motoStr) set OriginalDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to {findStr} set motoStr to text items of motoStr set AppleScript's text item delimiters to {repStr} set motoStr to motoStr as string set AppleScript's text item delimiters to OriginalDelimiters return motoStr end FindAndRep
tell application "Adobe InDesign CS2_J" tell active document tell page 1 set story orientation of story preferences of ¬ parent story of text frame 1 to vertical end tell end tell end tell
set inputFile to choose file with prompt "ファイルを選択してください" tell application "Adobe InDesign CS2_J" tell page 1 of document 1 set X to 14 set Y to 11 set W to 91 set H to 55 repeat with N1 from 1 to 2 set X2 to X + W * (N1 - 1) repeat with N2 from 1 to 5 set Y2 to Y + H * (N2 - 1) make new rectangle at beginning with properties ¬ {geometric bounds:{Y2, X2, Y2 + H, X2 + W}, ¬ stroke color:"None", fill color:"None"} set placeFile to place inputFile on rectangle 1 fit rectangle 1 given center content end repeat end repeat end tell end tell名刺の10枚面付け2 上と同じスクリプトですが一生懸命考えると6行になりました。
set inputFile to choose file with prompt "ファイルを選択してください" repeat with N1 from 1 to 10 tell application "Adobe InDesign CS2_J" to make new rectangle at beginning¬ of page 1 of document 1 with properties ¬ {geometric bounds:{(10 + ((N1 - 1) div 2) * 55), (15 + (N1 mod 2) * 91), ¬ (10 + ((N1 - 1) div 2) * 55) + 55, (15 + (N1 mod 2) * 91) + 91}, ¬ stroke color:"None", fill color:"None"} tell application "Adobe InDesign CS2_J" to place inputFile on rectangle 1 ¬ of page 1 of document 1 tell application "Adobe InDesign CS2_J" to fit rectangle 1 of page 1 ¬ of document 1 given center content end repeat
set myPer to 100 set NURI to 3 --塗り足し(0にすると塗り足しなし) set ANS to display dialog "ドキュメントの何ページ目から配置しますか?" ¬ default answer "1" set inddPage to text returned of ANS set inddPage to inddPage as integer set pdfPage to 1 set inputFile to choose file with prompt "pdfファイルを選択" set Fkind to kind of (info for inputFile) if Fkind is "PDF 書類" or Fkind is "Adobe PDF document" then --AcrobatでPDFを開きページ数を数える tell application "Adobe Acrobat 7.0 Professional" open inputFile set AllPage to count page of document 1 close document 1 end tell repeat AllPage times --AllPage分繰り返す。 set myError to my setEPS(pdfPage, inddPage, inputFile, NURI, myPer) set pdfPage to pdfPage + 1 set inddPage to inddPage + 1 if myError is "ERROR" then exit repeat end if end repeat end if --オリジナル関数setEPSの宣言 on setEPS(pdfPage, inddPage, inputFile, NURI, myPer) --ここより下でend tryより上を試す(エラーが出ても止まらないようにするため) try --"Adobe InDesign CS2_J"を呼ぶ tell application "Adobe InDesign CS2_J" set page number of PDF place preferences to pdfPage set PDF crop of PDF place preferences to crop media --"最前面のドキュメント"を呼ぶ tell active document --もし変数myPageのページが存在しないなら if not (exists of page inddPage) then --最後にページをつくる make page at end end if --ページの領域を変数myBに入れる{Y1,X1,Y2,X2}で返ってくる set myB to bounds of page inddPage --Y1より変数NURIを引いた分だけ変数Yに入れる set Y to (item 1 of myB) - NURI --X1より変数NURIを引いた分だけ変数Xに入れる set X to (item 2 of myB) - NURI --Y2よりY1を引き変数NURI*2を足した分だけ変数Hに入れる set H to (item 3 of myB) - (item 1 of myB) + NURI * 2 --X2よりX1を引き変数NURI*2を足した分だけ変数Wに入れる set W to (item 4 of myB) - (item 2 of myB) + NURI * 2 --"ページ"変数myPageを呼ぶ tell page (inddPage) --画像ボックスを作り変数myRectに入れる --(画像ボックスのプロパティは領域{Y, X, Y + H, X + W}、 --線幅0mm、ぬりなし、線の色もなし) set myRect to make rectangle at beginning with properties¬ {geometric bounds:{Y, X, Y + H, X + W}, stroke weight:0, ¬ fill color:"None", stroke color:"None"} --変数myRectの中にinputFileを配置し結果を変数EPSobjに入れる set PDFobj to place inputFile on myRect --EPSobjを呼ぶ tell PDFobj --水平方向の比率と垂直方向の比率を変数myPerにする set properties to {vertical scale:myPer, horizontal scale:myPer} end tell --myRectにセンター揃えの命令を送る fit myRect given center content end tell end tell end tell return "" on error return "ERROR" end try end setEPS
set myPer to 100 set NURI to 3 --塗り足し(0にすると塗り足しなし) tell application "Adobe InDesign CS2_J" set myVersion to version if "4.0." is not in myVersion then --InDesignのバーション確認 display dialog "Adobe InDesign CS2で使用してください。¬ InDesign2.0が起動している場合は一旦終了し、スクリプトも¬ 再起動してください。" return end if end tell set myFol to choose folder with prompt "フォルダを選択" set myFol to myFol as string set myPage to 1--変数myPageを1にしておく。 repeat with myFile in list folder myFol without invisibles --フォルダ内のアイテム分繰り返す --以降のif文までは選択ファイル配置&保存を参照 set this_item to (myFol & myFile) as alias set FType to file type of (info for this_item) set Fkind to kind of (info for this_item) if FType is "EPSF" or FType is "EPSP" or FType is "PDF " or ¬ FType is "8BPS" or FType is "TEXT" or ¬ Fkind is "Adobe Photoshop ファイル" or FType is "TIFF" or ¬ Fkind is "TIFF 書類" or Fkind is "EPS ファイル" then my setEPS(myPage, myFol & myFile, NURI, myPer) --オリジナル関数setEPSを呼び出す set myPage to myPage + 1 --変数myPageに1をプラスする。 end if end repeat on setEPS(myPage, inputFile, NURI, myPer) try tell application "Adobe InDesign CS2_J" tell active document if not (exists of page myPage) then make page at end end if set myB to bounds of page myPage set Y to (item 1 of myB) - NURI set X to (item 2 of myB) - NURI set H to (item 3 of myB) - (item 1 of myB) + NURI * 2 set W to (item 4 of myB) - (item 2 of myB) + NURI * 2 tell page (myPage) set myRect to make rectangle at beginning with properties ¬ {geometric bounds:{Y, X, Y + H, X + W}, stroke weight:0, ¬ fill color:"None", stroke color:"None"} set EPSobj to place inputFile on myRect tell EPSobj set properties to ¬ {vertical scale:myPer, horizontal scale:myPer} end tell fit myRect given center content end tell end tell end tell end try end setEPS
set this_item to choose file with prompt "配置ファイルを選択" set Fpath to this_item as string --変数Fpathにフルパスを入れる set Fpath to Fpath & ".indd" --フルパスに拡張子.inddを付けておく set Finfo to info for this_item --ファイルインフォメーションを調べる set FType to file type of Finfo --ファイルインフォメーションのファイルタイプを変数Ftypeに入れる set Fkind to kind of Finfo --ファイルインフォメーションのファイルカインドを変数Fkindに入れる --↓下記のような条件があえば。。。意外と条件にあわないEPSが多い。 if FType is "EPSF" or FType is "EPSP" or FType is "PDF " or FType is "8BPS" ¬ or FType is "TEXT" or Fkind is "Adobe Photoshop ファイル" or ¬ FType is "TIFF" or Fkind is "TIFF 書類" or Fkind is "EPS ファイル" then --オリジナル関数setEPS2を呼び出す my setEPS2(this_item, Fpath) end if --↓オリジナル関数setEPS2 on setEPS2(this_item, Fpath) tell application "Adobe InDesign CS2_J" --ドキュメントを作成 make document tell active document set myRect to make rectangle at beginning with properties ¬ {geometric bounds:{0, 0, 100, 100}, ¬ stroke weight:0, fill color:"None", stroke color:"None"} --とりあえずrectangle(ボックス)を作成100×100サイズ --線や塗りはなし set EPSobj to place this_item on myRect --ファイルを作成したボックスに配置する --(配置画像を変数EPSobjに入れる) set myB to geometric bounds of EPSobj --配置画像(変数EPSobj)の領域を調べる --geometric bounds は{Y1,X1,Y2,X2}で返ってくる set H to (item 3 of myB) - (item 1 of myB)--高さを取り出す set W to (item 4 of myB) - (item 2 of myB)--幅を取り出す if H < 297 and W < 210 then --A4縦より小さいなら set PW to 210 set PH to 297 else if H < 210 and W < 297 then --A4横より小さいなら set PW to 297 set PH to 210 else if H < 364 and W < 257 then --B4縦より小さいなら set PW to 257 set PH to 364 else if H < 257 and W < 364 then --B4横より小さいなら set PW to 364 set PH to 257 else --それ以外 if H > W then --A3縦 set PW to 297 set PH to 420 else --A3横 set PW to 420 set PH to 297 end if end if set properties of document preferences to {page height:PH, page width:PW} --ドキュメントのサイズを変更する。 set geometric bounds of myRect to {0, 0, PH, PW} --rectのサイズをページサイズにする fit myRect given center content --画像をセンターあわせにする。 save to Fpath --Fpathに保存する。 end tell end tell end setEPS2
set inputFile to "Macintosh HD:test.jpg" tell application "Adobe InDesign CS2_J" tell active document tell page 1 set EPSobj to place inputFile end tell end tell end tell領域を作っておきその領域に配置した後縮小する。
set inputFile to "Macintosh HD:test.jpg" set X to 10 set Y to 20 set W to 50 set H to 60 set myPer to 70 tell application "Adobe InDesign CS2_J" tell active document tell page 1 set myRect to make rectangle at beginning with properties ¬ {geometric bounds:{Y, X, Y + H, X + W}, stroke weight:0, ¬ fill color:"None", stroke color:"None"} --まずはボックスを作る set EPSobj to place inputFile on myRect --そのボックスに画像を入れる tell EPSobj set properties to {vertical scale:myPer, horizontal scale:myPer} --画像のサイズを変更する end tell fit myRect given center content --画像をセンターに入れる end tell end tell end tell
tell application "Adobe InDesign CS2_J" tell active document tell selection set myAngle to rotation angle as real --現在の回転を取り出す set rotation angle to myAngle - 0.1 --現在の回転から-0.1ひいたものにする。 end tell end tell end tell
tell application "Adobe InDesign CS2_J" tell active document fit rectangle 1 given content to frame -- fit rectangle 1 given content to frame/内容をフレームにあわせる -- fit rectangle 1 given center content/内容を中央に -- fit rectangle 1 given proportionally/短辺合わせ -- fit rectangle 1 given frame to content/フレームをあわせる -- fit rectangle 1 given fill proportionally/長辺合わせ end tell end tell
set mySnipet to "Macintosh HD:日程.inds" as string tell application "Adobe InDesign CS2_J" tell page 1 of document 1 place mySnipet end tell end tellこちらは出力です。出力も簡単なのですが書き出す時にレイヤーが非表示だと非表示のスニペットになってしまいます。要注意です。
tell application "Adobe InDesign CS2_J" tell document 1 tell layer 2 of page 1 export text frame 1 format InDesign snippet to mySnipet end tell end tell end tell
tell application "Adobe InDesign CS2_J" place asset asset "Nomi01" of library 1 on document 1 end tell
global lineW, mypt, myCol --グローバル変数の宣言。線幅とポイント数、色はグローバルにした set lineW to 0.1 --線幅0.1 set mypt to 2.83 --ポイントは2.83 tell application "Adobe InDesign CS2_J" tell active document set selectedItems to selection --選択アイテムを調べる if selectedItems is {} then --選択アイテムが無ければ display dialog "フレームを1つだけ選択してください。" return end if if not (exists (layers whose name is "TOMBO")) then --トンボレイヤーがなければ make layer with properties {name:"TOMBO"}--レイヤーを作る end if set myCol to color "Registration" -- 変数myColはレジストレーションにしておく if number of selectedItems is 1 then --選択アイテムが1つなら set selItem to item 1 of selectedItems --選択アイテムの1つめを取り出す。(変数selectedItemsはリストだから) set myParent to parent of selItem --選択アイテムの親オブジェクトを調べる。 --(ページ番号が入ると思われる。) --※こまかいエラー処理をしていないのはご容赦 set myBounds to geometric bounds of selItem --選択アイテムの領域 set X to item 2 of myBounds--X座標 set Y to item 1 of myBounds--Y座標 set W to (item 4 of myBounds) - (item 2 of myBounds)--幅 set H to (item 3 of myBounds) - (item 1 of myBounds)--高さ set gItm to {} as list--変数gItmをリストとして初期化しておく。 --左上 set gItm to gItm & my drowLine(X - 13, X - 3, Y, Y, myParent) --オリジナル関数dorwLineを呼び出し、 --結果(ラインオブジェクトが返ってくる)を変数gItemに入れる set gItm to gItm & my drowLine(X - 13, X, Y - 3, Y - 3, myParent) set gItm to gItm & my drowLine(X - 3, X - 3, Y - 13, Y, myParent) set gItm to gItm & my drowLine(X, X, Y - 13, Y - 3, myParent) --上センター set gItm to gItm & my drowLine(X + W / 2, X + W / 2, Y - 13, Y - 3, myParent) set gItm to gItm & my drowLine(X + W / 2 - 5, X + W / 2 + 5, Y - 7, Y - 7, myParent) set gItm to gItm & my drowEllipse(X + W / 2 - 2, Y - 7 - 2, 4, 4, myParent) --右上 set gItm to gItm & my drowLine(X + W + 3, X + W + 13, Y, Y, myParent) set gItm to gItm & my drowLine(X + W, X + W + 13, Y - 3, Y - 3, myParent) set gItm to gItm & my drowLine(X + W + 3, X + W + 3, Y - 13, Y, myParent) set gItm to gItm & my drowLine(X + W, X + W, Y - 13, Y - 3, myParent) --左センター set gItm to gItm & my drowLine(X - 13, X - 3, Y + H / 2, Y + H / 2, myParent) set gItm to gItm & my drowLine(X - 7, X - 7, Y + H / 2 - 5, Y + H / 2 + 5, myParent) set gItm to gItm & my drowEllipse(X - 7 - 2, Y + H / 2 - 2, 4, 4, myParent) --右センター set gItm to gItm & my drowLine(X + W + 3, X + W + 13, Y + H / 2, Y + H / 2, myParent) set gItm to gItm & my drowLine(X + W + 7, X + W + 7, Y + H / 2 - 5, Y + H / 2 + 5, myParent) set gItm to gItm & my drowEllipse(X + W + 7 - 2, Y + H / 2 - 2, 4, 4, myParent) --左下 set gItm to gItm & my drowLine(X - 13, X - 3, Y + H, Y + H, myParent) set gItm to gItm & my drowLine(X - 13, X, Y + H + 3, Y + H + 3, myParent) set gItm to gItm & my drowLine(X - 3, X - 3, Y + H + 13, Y + H, myParent) set gItm to gItm & my drowLine(X, X, Y + H + 13, Y + H + 3, myParent) --下センター set gItm to gItm & my drowLine(X + W / 2, X + W / 2, Y + H + 13, Y + H + 3, myParent) set gItm to gItm & my drowLine(X + W / 2 - 5, X + W / 2 + 5, Y + H + 7, Y + H + 7, myParent) set gItm to gItm & my drowEllipse(X + W / 2 - 2, Y + H + 7 - 2, 4, 4, myParent) --右上 set gItm to gItm & my drowLine(X + W + 3, X + W + 13, Y + H, Y + H, myParent) set gItm to gItm & my drowLine(X + W, X + W + 13, Y + H + 3, Y + H + 3, myParent) set gItm to gItm & my drowLine(X + W + 3, X + W + 3, Y + H + 13, Y + H, myParent) set gItm to gItm & my drowLine(X + W, X + W, Y + H + 13, Y + H + 3, myParent) make group with properties {group items:gItm} --変数gItemをグループ化する。 end if end tell end tell --オリジナル関数dorwLine on drowLine(X1, X2, Y1, Y2, myParent) set buf to {Y1, X1, Y2, X2} tell application "Adobe InDesign CS2_J" tell myParent--変数myParentにはおそらくページが入っている。 make graphic line with properties {geometric bounds:buf, ¬ fill color:"None", stroke color:myCol, stroke weight:lineW * mypt, ¬ item layer:"TOMBO"} --"TOMBO"レイヤーに線を引く end tell end tell end drowLine on drowEllipse(X1, Y1, W1, H1, myParent) set buf to {Y1, X1, Y1 + H1, X1 + W1} tell application "Adobe InDesign CS2_J" tell myParent make ovals with properties {geometric bounds:buf, ¬ fill color:"None", stroke color:myCol, stroke weight:lineW * mypt, ¬ item layer:"TOMBO"} --マルを作成する end tell end tell end drowEllipse
tell application "Adobe InDesign CS2_J" tell document 1 override item 1 of master page items of page 1 destination page page 1 end tell end tell
tell application "Adobe InDesign CS2_J" tell document 1 tell page 1 tell text frame "Sname" set contents to "商品名" end tell end tell end tell end tell
tell application "Adobe InDesign CS2_J" tell active document tell spread 1--スプレッド1の set sp1Count to count pages--ページ数を調べる end tell end tell end tell display dialog "スプレッド1は" & sp1Count & "ページです"
tell application "Adobe InDesign CS2_J" tell active document set PageCount to count page end tell end tell
tell application "Adobe InDesign CS2_J" set LayObj to layer "LINE" of active document set Ws to 0.2 set colName to "M100Y100" set C to 0 set M to 100 set Y to 100 set K to 0 tell active document try set myCol to color colName --変数myColにカラーオブジェクトを入れる on error--失敗したら set myCol to make color with properties ¬ {name:colName, color value:{C, M, Y, K}} --変数myColにカラーオブジェクトを作る end try end tell tell page 1 of active document make graphic line with properties ¬ {geometric bounds:{"12 mm", "10 mm", "109 mm", "10 mm"}, ¬ fill color:"None", stroke color:myCol, stroke weight:Ws, ¬ item layer:LayObj} --ライン作成。塗りがなしはfill color:"None" --2.0ではfill color:none end tell end tell
tell application "Adobe InDesign CS2_J" tell active document if not (exists (layers whose name is "IMG")) then --同じ名前のレイヤーがあればエラーになるのでまず調べる make layer with properties {name:"IMG"} --なければレイヤーをつくる end if end tell end tell
tell application "Adobe InDesign CS2_J" set LayObj to layer "写真" of active document --写真レイヤーを変数LayObjへ入れる tell active document tell page 1 set myGuide to make guide with properties ¬ {orientation:horizontal, location:40, item layer:LayObj} --写真レイヤーに横ガイドをひく end tell end tell end tell
tell application "Adobe InDesign CS2_J" tell active document set spCount to count master spread --マスターページのスプレッド数を調べる repeat with N from 1 to spCount --マスターページ分繰り返す tell master spread N delete (every guide whose orientation is horizontal) --横ガイドを全て消す end tell end repeat end tell end tell
tell application "Adobe InDesign CS2_J" set Dcount to count document repeat with N from 1 to Dcount set myName to name of document N as string set myPath to (file path of document N) as string set myPDFpreset to PDF export preset "[PDF/X-1a]" set newFile to myPath & myName & ".pdf" export document N format PDF type to newFile using myPDFpreset end repeat end tell
tell application "Adobe InDesign CS2_J" make document with properties {page height:297, page width:210} end tell作成する2プロパティも同時設定
tell application "Adobe InDesign CS2_J" set myDocument to make document --ドキュメントを作成(作成されたドキュメントは変数myDocumentに入る) set properties of document preferences of myDocument to ¬ {pages per document:10, pages per spread:1, ¬ page width:"210 mm", page height:"297 mm"} --プロパティの設定。document preferencesを使う。 --pages per document ドキュメントのページ数 --pages per spread スプレッド当たりのページ数(2なら見開き) end tell保存せずに閉じる(Illustratorと同じ)
tell application "Adobe InDesign CS2_J" close document 1 saving no end tell保存する
set Fpath to "macintosh HD:test.indd" tell application "Adobe InDesign CS2_J" save document 1 to Fpath end tell
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
tell application "Adobe Illustrator" open file "Macintosh HD:TEST10.ai" without dialogs end tell
tell application "Adobe Illustrator" tell document 1 set pathCount to count path items repeat with pathNum from 1 to pathCount set pathStrokeWidth to stroke width of path item pathNum if 0.6 < pathStrokeWidth and pathStrokeWidth < 0.7 then set stroke width of path item pathNum to 0.283 else if 0.7 < pathStrokeWidth then set stroke width of path item pathNum to pathStrokeWidth / 2 else set stroke width of path item pathNum to 0.283 end if end repeat end tell end tell
global lineW, C, M, Y, K, pt set lineW to 0.05 --色を入力単位% set C to 100 set M to 100 set Y to 100 set K to 100 set pt to 2.83466796875 tell application "Adobe Illustrator" tell document 1 set selectedItems to selection if selectedItems is {} then display dialog "四角をを選択ツールで選択してください。" return end if repeat with selItem in selectedItems set myB to geometric bounds of selItem my makeTombo(myB) end repeat end tell end tell on makeTombo(myB) set X1 to (item 1 of myB) / pt set Y1 to (item 2 of myB) / pt set X2 to (item 3 of myB) / pt set y2 to (item 4 of myB) / pt set myGroup to my makeGroup() my makeLine(X1 - 13, Y1, X1 - 3, Y1, myGroup) --横罫左上 my makeLine(X1 - 13, Y1 + 3, X1, Y1 + 3, myGroup) --横罫左上 my makeLine(X1, Y1 + 13, X1, Y1 + 3, myGroup) --縦罫左上 my makeLine(X1 - 3, Y1 + 13, X1 - 3, Y1, myGroup) --縦罫左上 my makeLine(X1 - 13, y2, X1 - 3, y2, myGroup) --横罫左下 my makeLine(X1 - 13, y2 - 3, X1, y2 - 3, myGroup) --横罫左下 my makeLine(X1, y2 - 13, X1, y2 - 3, myGroup) --縦罫左下 my makeLine(X1 - 3, y2 - 13, X1 - 3, y2, myGroup) --縦罫左下 my makeLine(X2 + 13, Y1, X2 + 3, Y1, myGroup) --横罫右上 my makeLine(X2 + 13, Y1 + 3, X2, Y1 + 3, myGroup) --横罫右上 my makeLine(X2, Y1 + 13, X2, Y1 + 3, myGroup) --縦罫右上 my makeLine(X2 + 3, Y1 + 13, X2 + 3, Y1, myGroup) --縦罫右上 my makeLine(X2 + 13, y2, X2 + 3, y2, myGroup) --横罫右下 my makeLine(X2 + 13, y2 - 3, X2, y2 - 3, myGroup) --横罫右下 my makeLine(X2, y2 - 13, X2, y2 - 3, myGroup) --縦罫右下 my makeLine(X2 + 3, y2 - 13, X2 + 3, y2, myGroup) --縦罫右下 my makeLine(X1 - 13, Y1 + (y2 - Y1) / 2, X1 - 3, Y1 + (y2 - Y1) / 2, myGroup) --横罫左中 my makeLine(X1 - 8, Y1 + (y2 - Y1) / 2 - 5, X1 - 8, Y1 + (y2 - Y1) / 2 + 5, myGroup) --縦罫左中 my makeEllipse(X1 - 8 - 1.5, (Y1 + (y2 - Y1) / 2) + 1.5, 3, 3, myGroup) --○丸左中 my makeLine(X2 + 13, Y1 + (y2 - Y1) / 2, X2 + 3, Y1 + (y2 - Y1) / 2, myGroup) --横罫左中 my makeLine(X2 + 8, Y1 + (y2 - Y1) / 2 - 5, X2 + 8, Y1 + (y2 - Y1) / 2 + 5, myGroup) --縦罫左中 my makeEllipse(X2 + 8 - 1.5, (Y1 + (y2 - Y1) / 2) + 1.5, 3, 3, myGroup) --○丸右中 my makeLine(X1 + (X2 - X1) / 2, Y1 + 13, X1 + (X2 - X1) / 2, Y1 + 3, myGroup) --縦罫中上 my makeLine(X1 + (X2 - X1) / 2 - 5, Y1 + 8, X1 + (X2 - X1) / 2 + 5, Y1 + 8, myGroup) --横罫中上 my makeEllipse(X1 + (X2 - X1) / 2 - 1.5, Y1 + 8 + 1.5, 3, 3, myGroup) --○丸中上 my makeLine(X1 + (X2 - X1) / 2, y2 - 13, X1 + (X2 - X1) / 2, y2 - 3, myGroup) --縦罫中下 my makeLine(X1 + (X2 - X1) / 2 - 5, y2 - 8, X1 + (X2 - X1) / 2 + 5, y2 - 8, myGroup) --横罫中下 my makeEllipse(X1 + (X2 - X1) / 2 - 1.5, y2 - 8 + 1.5, 3, 3, myGroup) --○丸中下 end makeTombo on makeLine(X1, Y1, X2, y2, myGroup) set X1 to X1 * pt set Y1 to Y1 * pt set X2 to X2 * pt set y2 to y2 * pt set W to lineW * pt tell application "Adobe Illustrator" tell document 1 make new path item at end of myGroup with properties ¬ {stroke color:{cyan:C, magenta:M, yellow:Y, black:K}, ¬ stroke width:W, entire path:{{class:path point info, ¬ anchor:{X1, Y1}}, {class:path point info, anchor:{X2, y2}}}} end tell end tell end makeLine on makeEllipse(X1, Y1, W, H, myGroup) tell application "Adobe Illustrator" tell document 1 set X1 to X1 * pt set Y1 to Y1 * pt set myW to W * pt set myH to H * pt set W to lineW * pt make new ellipse at end of myGroup with properties ¬ {filled:false, stroked:true, ¬ stroke color:{cyan:C, magenta:M, yellow:Y, black:K}, ¬ width:myW, height:myH, position:{X1, Y1}, stroke width:W} end tell end tell end makeEllipse on makeGroup() tell application "Adobe Illustrator" tell document 1 if exists group item "TOMBO" then set myGroup to group item "TOMBO" else set myGroup to make group item at beginning ¬ with properties {name:"TOMBO"} end if end tell end tell return myGroup end makeGroup
tell application "Adobe Illustrator" tell document 1 rotate placed item 1 angle 5 end tell end tell
tell application "Adobe Illustrator" tell document 1 make new group item at end with properties {name:KeyWord} --レイヤーの一番後ろにグループが作られる make new placed item at end of group item KeyWord ¬ with properties {file path:alias Fpath, position:{X, Y}} set clipped of group item KeyWord to true end tell end tell
set filePath to (choose file) as string set X to 10 set Y to 10 set mySize to 50 set pt to 2.83 set mySize to mySize * pt set X to X * pt set Y to Y * pt tell application "Adobe Illustrator" --下記はリンク set placedRef to make new placed item in document 1 ¬ with properties {file path:alias filePath} --下記は埋め込み --set placedRef to make new group item at end with data alias filePath set PW to width of placedRef set PH to height of placedRef if PW > PH then set buf to PW else set buf to PH end if set Percent to mySize / buf set W to PW * Percent set H to PH * Percent set properties of placedRef to {position:{X, Y}, height:H, width:W} end tell
tell application "Adobe Illustrator" tell document 1 set selectedItems to selection if selectedItems is {} then display dialog "text frameを選択ツールで選択してください。" return end if repeat with selItem in selectedItems if class of selItem is text frame then set Cnum to count characters of selItem repeat with N from 1 to Cnum - 1 set TXT1 to contents of character N of selItem set TXT2 to contents of character (N + 1) of selItem if TXT1 is in "0123456789,." and TXT2 is in "0123456789,." then set alternate glyphs of character N of selItem¬ to half width --等幅半角字形 set alternate glyphs of character (N + 1) of selItem¬ to half width --等幅半角字形 end if end repeat end if end repeat end tell end tell
set TexData to "" set FileName to (choose file name) as string tell application "Adobe Illustrator" tell document 1 set boxnum to count text frames repeat with N from 1 to boxnum set TexData to TexData & contents of text frame N & return & return end repeat end tell end tell open for access file FileName with write permission write TexData to file FileName close access file FileName
tell application "Adobe Illustrator" tell document 1 tell text frame "A" --1文字目を"あいうえお"にする set contents of character 1 to "あいうえお" --再終行を"かきくけこ"にする set contents of paragraph -1 to "かきくけこ" end tell end tell end tell
tell application "Adobe Illustrator" tell document 1 repeat with tFrame in every text frame if kind of tFrame is {area text} then if my overflow(tFrame) then display dialog "オーバーフロー:" & contents of tFrame end if end if end repeat end tell end tell on overflow(tFrame) set OriginalDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to "" tell application "Adobe Illustrator" set myLastP to (contents of every paragraph of tFrame) as string set myLastL to (contents of every line of tFrame) as string set AppleScript's text item delimiters to OriginalDelimiters if myLastP is not myLastL then set AppleScript's text item delimiters to OriginalDelimiters return true else set AppleScript's text item delimiters to OriginalDelimiters return false end if end tell end overflow
set pt to 2.83464 set Q to 0.25 * pt tell application "Adobe Illustrator" tell document 1 set mySelObjList to selection--選択されたオブジェクトを調べる repeat with mySelObj in mySelObjList--選択分繰り返す if class of mySelObj is text frame then--もしtext frameなら tell mySelObj --プロパティを調べる get properties of character 1 --内容を変更する set contents to "あいうえお" & return & "かきくけこ" --フォントを変える set text font of characters 1 thru 5 to ¬ text font "Osaka" of application "Adobe Illustrator" --サイズを変える set size of characters 1 thru 5 to 13 * Q --ベースラインシフト set baseline shift of character 1 of paragraph 1 to 2 --横変倍 set horizontal scale of character 1 of paragraph 1 to 200 --縦変倍 set vertical scale of character 2 of paragraph 1 to 200 --カーニング set kerning of character 2 of paragraph 1 to -300 --塗り set fill color of character 3 of paragraph 2 to ¬ {cyan:0, magenta:50, yellow:100, black:0} --線幅 set stroke weight of character 3 of paragraph 2 to 0.2 --線の色 set stroke color of character 3 of paragraph 2 to ¬ {cyan:0, magenta:100, yellow:100, black:0} --テキストフレームの幅を変更(長体がかかる) --これを行うと線幅等が消えてしまう要注意 set width to 10 * pt end tell end if end repeat end tell end tell
tell application "Adobe Illustrator" tell document 1 set mySelObjList to selection --選択されたオブジェクトを調べる repeat with mySelObj in mySelObjList --選択分繰り返す if class of mySelObj is text frame then --もしtext frameなら my chouTai(mySelObj) end if end repeat end tell end tell on chouTai(mySelObj) tell application "Adobe Illustrator" set myW to width of mySelObj --text frameの幅を調べる --長体horizontal scaleを調べる(平体はvertical scale)-- --Illustrator10ではscalingで縦横の比率がとれる set SCL to horizontal scale of paragraph 1 of mySelObj --横幅10倍サイズで複製する set dupTextObj to duplicate mySelObj to beginning of document 1 ¬ with properties {width:myW * 10} --長体も10倍になるので長体を101%にする(なぜか100%にはならない) if SCL = 100 then set SCL to 101 end if set horizontal scale of paragraph 1 of dupTextObj to SCL --行数を調べる set Pcount to count paragraph of dupTextObj if Pcount > 1 then --行数が2行以上なら display dialog "1行のテキストのみに有効です。" return --処理終了 end if --行揃えを左にしておく。両揃えだと正しくはかれない set justification of paragraph 1 of dupTextObj to left --アウトライン作成 set outLinePath to convert to paths dupTextObj --アウトラインの領域を調べる set myBounds to control bounds of outLinePath --control/visible --長さを取り出す set myW2 to (item 3 of myBounds) - (item 1 of myBounds) --(width of TBOX) delete outLinePath --アウトラインは消す if myW < myW2 then --もしアウトラインの方がtext frameよりも長ければ set myWhi to myW / myW2 --比率を求めて set SCL to SCL * myWhi - 1--誤差が出るので1%マイナスする set horizontal scale of paragraph 1 of mySelObj to SCL end if end tell end chouTai
tell application "Adobe Illustrator" tell document 1 tell text frame 1 tell paragraph 1 set justification to right --right以外にも下記の種類がある --center/full justify/full justify last line center/ --full justify last line left/full justify last line right --/left/right end tell end tell end tell end tell
tell application "Adobe Illustrator" tell document 1 tell layer 1 tell text frame 1 get text orientation --vertical=縦--horizontal=横 end tell end tell end tell end tellIllustrator10は
text art item
set pt to 2.83464 tell application "Adobe Illustrator" tell document 1 tell path item 1 set filled to false --塗りをなしにする set fill color to {cyan:0, magenta:0, yellow:0, black:0} --塗りを白にする set stroked to true --線の設定をありにする set stroke color to {cyan:0, magenta:100, yellow:50, black:0} --線をM100Y50にする set stroke width to 0.2 * pt end tell end tell end tellいっぺんに設定するにはset propertiesを使う
set pt to 2.83464 tell application "Adobe Illustrator" tell document 1 tell path item 1 set properties to {filled:false, ¬ fill color:{cyan:0, magenta:0, yellow:0, black:0}, ¬ stroked:true, ¬ stroke color:{cyan:0, magenta:100, yellow:50, black:0}, ¬ stroke width:0.2 * pt} end tell end tell end tellガイドにする
tell application "Adobe Illustrator" tell document 1 set guides of path item 1 to true end tell end tell
tell application "Adobe Illustrator" tell document 1 make new layer at beginning with properties {name:"TESTレイヤー"} end tell end tellレイヤーのロック
tell application "Adobe Illustrator" tell document 1 --レイヤー1をロックする set locked of layer 1 to true --"画像"という名前のレイヤーをロックする set locked of layer "画像" to true end tell end tell
tell application "Adobe Illustrator" make new document with properties {color space:CMYK} end tell保存せずに閉じる
tell application "Adobe Illustrator" close document 1 saving no end tell保存する
set fileRef to "Macintosh HD:test.eps" as text tell application "Adobe Illustrator" --通常のAI保存 save document 1 in file fileRef --eps保存 save document 1 in file fileRef as eps with options ¬ {class:EPS save options, compatibility:Illustrator 10, embed all fonts:true} --PDF保存 save document 1 in file fileRef as eps with options ¬ {class:PDF save options, compatibility:Acrobat 4, preserve editability:true} end tellgif書き出し
set SaveFolder to choose folder with prompt "保存フォルダを選択してください" tell application "Adobe Illustrator" activate tell document 1 set saveF to (SaveFolder as text) & "myPicture.gif" export to file saveF as GIF with options ¬ {class:GIF export options, horizontal scaling:200, vertical scaling:200} end tell end tellロックされていない一旦すべて非表示にして、その後レイヤーを順に表示してgif出力。Web用のボタンをつくるのに便利なスクリプトです。
set SaveFolder to choose folder with prompt "保存フォルダを選択" tell application "Adobe Illustrator" activate tell document 1 set countLayer to count layer--レイヤーの数を数える repeat with t from 1 to countLayer--レイヤー分繰り返す if layer t is not locked then --もしロックされていなければ --ロックされていないレイヤーをぜんぶ非表示にする set visible of layer t to false end if end repeat repeat with t from 1 to countLayer--レイヤー分繰り返す if layer t is not locked then--もしロックされていなければ set visible of layer t to true--レイヤーを表示する set OutName to name of layer t--レイヤー名を取り出す set saveF to (SaveFolder as text) & (OutName as text) & ".gif" --レイヤー名でファイル名を作成 export to file saveF as GIF--レイヤー名でGIF書き出し --export to file saveF as JPEG/Photoshop/SVG/PNG8/PNG24 --などいろいろ選べる set visible of layer t to false--レイヤーを非表示にする end if end repeat end tell end tell
scale horizontal scale Wper vertical scale Hper line scale Wper ¬ about top left with transforming objects, transforming fill patterns,¬ transforming fill gradients and transforming stroke patternsを使って変倍したあとpositionで移動させます。
scaleのオプションパラメータは以下のとおり horizontal scale 120--左右の変倍比率(120だと120%) vertical scale 120-- 天地の変倍比率 line scale 120-- 線幅の変倍比率 about top left--左上基準で変倍 bottom rightで右下基準 centerで中心基準 with transforming objects,--効果も変倍する transforming fill patterns,--塗りのパターンも変倍する transforming fill gradients --グラデも変倍する and transforming stroke patterns--線のパターンも変倍する下記が変倍のサンプルスクリプトです。希望の大きさと現在の大きさの比率を出して変倍してから移動しています。
tell application "Adobe Illustrator" tell document 1 tell group item 1 set properties to {position:{0, 10}, width:100, height:200} --これをすると線幅やアピアランスが消えてしまう --(Illustrator10では大丈夫) set myCB to control bounds --オブジェクトを選択してドラッグするときに表示される輪郭。 --オブジェクトよりひとまわり大きい。 set myGB to geometric bounds --オブジェクトのアンカーポイントぴったりのサイズ set myVB to visible bounds --オブジェクトに線の設定がされていれば線幅も加えたサイズになる。 set myX to item 1 of myGB set myY to item 2 of myGB set myW to (item 3 of myGB) - myX set myH to (item 4 of myGB) - myY set Wper to 100 / myW * 100 set Hper to 200 / myH * 100 scale horizontal scale Wper vertical scale Hper line scale Wper ¬ about top left with transforming objects, transforming fill patterns,¬ transforming fill gradients and transforming stroke patterns set position to {0, 10} end tell end tell end tell
tell application "Adobe Illustrator" tell document 1 make new rectangle at beginning with properties ¬ {bounds:{0, 200, 200, 50}, fill color:{cyan:100, magenta:100, yellow:0, black:0}} end tell end telltext frameを作成(ポイントテキストとエリアテキスト)
tell application "Adobe Illustrator" tell document 1 --ポイントテキスト make new text frame at beginning with properties ¬ {position:{0, 200}, contents:"あいうえお"} --エリアテキスト make new text frame at beginning with properties¬ {geometric bounds:{100, 90, 160, 180}, contents:"かきくけこ", kind:area text} end tell end tellpath itemを作成(entire pathで線の両端の座標を指定する。)
tell application "Adobe Illustrator" tell document 1 make new path item at end with properties ¬ {stroke color:{cyan:C, magenta:M, yellow:Y, black:K}, ¬ stroke width:W, entire path:{{class:path point info, anchor:{X1, Y1}}, ¬ {class:path point info, anchor:{X2, y2}}}} end tell end tell
tell application "Adobe Illustrator" tell document 1 duplicate text frame 1 to end --背面に複製 duplicate text frame 1 to beginning --前面に複製 duplicate path item 1 to end of layer 2 --レイヤー2の背面に複製 end tell end tell移動する
tell application "Adobe Illustrator" tell document 1 move text frame 1 to end --背面に移動 move text frame 1 to beginning --前面に移動 move path item 1 to end of layer 2 --レイヤー2の背面に移動 end tell end tellオブジェクトが存在するか
tell application "Adobe Illustrator" tell document 1 if exists path item 1 then delete path item 1 end if end tell end tell
set pt to 2.83464--変数ptに2.83464を入れておく tell application "Adobe Illustrator" tell document 1 set selectedItemList to every page item whose selected is true --選択されたオブジェクトを調べる(listで返ってくる) repeat with selectedItem in selectedItemList --選択オブジェクト分繰り返す。 set myPos to position of selectedItem--座標を調べる(listで返る) set myX to item 1 of myPos--X座標を取り出す set myY to item 2 of myPos--Y座標を取り出す set position of selectedItem to {myX + 10 * pt, myY} --新しい座標(X+10×2.83464)にする end repeat end tell end tell
make: Make a new element make new type class -- the class of the new element. at location reference -- the location at which to insert the element [with data anything] -- the initial data for the element [with properties record] -- the initial values for the properties of the element Result: reference -- to the new object(s)makeというコマンドの次の行にnew type classとありさらに次にat location referenceとあります。これは
make new 作りたいオブジェクトのクラス at 場所という書き方になります。その後の[]でくくられている部分は省略可能です。Resultにreferenceとありますがこれは返り値で新しく出来たオブジェクトが返ってきます。では作りたいオブジェクトのクラスですが、先ほどget propertiesで調べたtext frameクラスを渡してみましょう。場所は最前面につくるのならbeginningでいいでしょう。
tell application "Adobe Illustrator" tell document 1 make text frame at beginning end tell end tellぽつんと小さなオブジェクトが出来ました。これがスクリプトから作成したtext frameです。さきほど省略したwith propertiesを使ってみましょう。with properties recordと書いてあるのでwith properties {○○:〜〜}という使い方になります。text frameのプロパティは先ほど調べました。その中でcontentsを使ってみましょう。
tell application "Adobe Illustrator" tell document 1 make text frame at beginning with properties {contents:"あああ"} end tell end tellほかにもコマンドには
close: --ドキュメントを閉じる close document 1 saving no--保存せずに count reference -- オブジェクトの数を数える count taxt frames delete: -- オブジェクトを消す delete text frame 1 duplicate: --複製する duplicate text frame 1 to end exists: --オブジェクトが存在するか? if exists text frame 1 then〜end if move: --オブジェクトを動かす move text frame 1 to end of layer 1 open: --ファイルを開く open alias "Macintosh HD:test.ai" save: --ファイルを保存する save document 1 in file "Macintosh HD:test.ai" as Illustratorなどがあります。まだまだ他にもいろいろありますので後述します。
Class text frame: Text frame item Plural form: text frames Elements: character by numeric index, as a range of elements, before/after another element, satisfying a test insertion point by numeric index, as a range of elements, before/after another element, satisfying a test line by numeric index, as a range of elements, before/after another element, satisfying a test paragraph by numeric index, as a range of elements, before/after another element, satisfying a test text by numeric index, as a range of elements, before/after another element, satisfying a test word by numeric index, as a range of elements, before/after another element, satisfying a test Properties:大量にでてきますが--より右に書いてあるのが解説です。 Elementsは要素です。character(キャラクター)が書いてありますが、text frameの要素にcharacterがあるということです。これをスクリプトにすると下記のようにさらに深い階層になります。characterの用語辞書はText Suiteに書かれています。page item [r/o] -- subclass of page item properties record -- all of this object's properties returned in a single record anchor list -- the position of the anchor point (start of base line for point text) column count integer -- the column count in the text frame (area text only) column gutter real -- the column gutter in the text frame (area text only) content variable anything -- the content variable bound to this text art item contents Unicode text -- the text contents of this text frame end T value real -- the end position of text along a path, as a value relative to the path's segments (path text only) flow links horizontally boolean -- Flow text between linked frame horizontally first. (area text only) kind area text/path text/point text [r/o] -- the type of a text frame item matrix matrix [r/o] -- The transformation matrix of the text frame object next frame text frame -- the linked text frame following this one optical alignment boolean -- is the optical alignment active? previous frame text frame -- the linked text frame preceding this one row count integer -- the row count in the text frame (area text only) row gutter real -- the row gutter in the text frame (area text only) selection a list of text [r/o] -- the selected text (ranges) in the story spacing real -- the amount of spacing (path text only) start T value real -- the start position of text along a path, as a value relative to the path's segments (path text only) story story [r/o] -- the story of the text frame text orientation horizontal/vertical -- the orientation of the text in the frame text path text path [r/o] -- the path for the text frame (area and path text) text range text [r/o] -- the text range of the text frame
tell application "Adobe Illustrator" tell document 1 tell text frame 1 tell character 2 get properties end tell end tell end tell end tellPropertiesがプロパティですね。この値を変更することによって、Illustratorを操ることが出来ます。
contents Unicode text -- the text contents of this text frameはプロパティcontentsの値はユニコードテキストだということと、--以下の説明をみるとtext frameの内容だということがわかります。
row count integer -- the row count in the text frame (area text only)というのはrow count(段組みの段数)がinteger(整数)で返ってくることがわかります。 [r/o] と書いてあるのはread onlyのため変更することは出来ません。
kind area text/path text/point text [r/o] -- the type of a text frame itemkindというのは種類でarea textかpath textかpoint textで値が返ってきます。テキストボックスを作ればarea textでクリックして文字を作ればpoint textで、ベジェ曲線に沿うようなのはpath textです。こちらも[r/o]なので変更不可です。(実はIllustrator10では変更できましたが変更すると変な形になっていました。)
tell application "Adobe Illustrator"--Illustratorの tell document 1--最前面のドキュメントの tell page item 1--最前面のアイテムの get properties--プロパティを調べる end tell end tell end tellこのget propertiesは「QuarkXPressを操ろう」をNiftyのFPRINTフォーラムで連載されてい鎌田さんゆずりの方法でこれを初めて知って以来いろんなオブジェクトにget propertiesしてきました。いまAppleScriptが使えるようになったのもこのget propertiesのおかげです。 さていろいろな値がかえってきました。抜粋します。
contents:"あいうえお", text orientation:horizontal, position:{86.22216796875, 641.115234375}, width:60.0, height:15.0361328125, name:"", class:text frame, index:1まず注目はclassです。このテキストのクラス名はtext frameだということがわかります。indexは1なのでpage item 1ではなくてtext frame 1で指定する方が良いでしょう。contents:"あいうえお"とあります。これを変えてみましょう。変更するにはAppleScriptで変数に値を入れる方法と同じです。 set 変数 to ○○ でしたね。では
tell application "Adobe Illustrator"--Illustratorの tell document 1--最前面のドキュメントの tell text frame 1--最前面のtext frameの set contents to "かきくけこ"--contentsを"かきくけこ"にする。 end tell end tell end tellこれを動かしてください。文字内容が変わりましたね。
tell application "Adobe Illustrator" tell document 1 tell text frame 1 set position to {100, 100} end tell end tell end tellを動かすと文字の場所が変わります。場所とcontentsを一度にセットすることも出来ます。
tell application "Adobe Illustrator" tell document 1 tell text frame 1 set properties to {position:{100, 100}, contents:"かきくけこ"} end tell end tell end tellもちろんget propertiesだけではAppleScriptでInDesignをコントロールするだけの情報を調べるのは困難です。text frame 1でget propertiesしてもフォントやカラーのプロパティはありませんでした。実際フォントやカラーはtext frameのプロパティではなくtext frameの要素であるparagraphやcharacterのプロパティです。しかし、それを調べるのはget propertiesだけでは無理です。このようにもっといろいろ調べたい場合は後述する用語辞書やリファレンスを見ます。
tell application "Adobe InDesign CS2_J"--InDesignの tell document 1--最前面のドキュメントの tell page 1--1ページ目の tell text frame 1--最前面のテキストフレームの set contents to "あいうえお"--内容を"あいうえお"にする。 end tell end tell end tell end tellとういうように階層になっています。InDesignのドキュメントの1ページ目のテキストフレームという意味。ofを使うと下のように簡略化して書けます。
tell application "Adobe InDesign CS2_J" tell text frame 1 of page 1 of document 1 set contents to "あいうえお" end tell end tell文字スタイルの数を取り出すときもドキュメントの文字スタイルの数というように階層をたどっていって取り出します。
tell application "Adobe InDesign CS2_J" tell document 1 set myChrCount to count character styles--文字スタイルの数を数える。 end tell end tell
set AAA to choose from list {"ぐー", "ちょき", "ぱー"} with prompt "さいしょはぐー!" if AAA is not {"ぐー"} then display dialog "最初はぐーだよ" end if set AAA to choose from list {"ぐー", "ちょき", "ぱー"} with prompt "じゃーんけーん" set myJanken to AAA--わたしの手はmyJankenに入る set BBB to random number from 1 to 3--1から3のランダムな数字がBBBに入る if BBB is 1 then--もし1なら set asJanken to {"ぐー"}--変数asJankenを {"ぐー"}にする else if BBB is 2 then set asJanken to {"ちょき"} else set asJanken to {"ぱー"} end if if myJanken is asJanken then display dialog "あいこだよ" else if myJanken is {"ぱー"} and asJanken is {"ぐー"} then display dialog "わたしの手は" & asJanken & "でした。あなたの勝ちです。" else if myJanken is {"ぐー"} and asJanken is {"ちょき"} then display dialog "わたしの手は" & asJanken & "でした。あなたの勝ちです。" else if myJanken is {"ちょき"} and asJanken is {"ぱー"} then display dialog "わたしの手は" & asJanken & "でした。あなたの勝ちです。" else if myJanken is {"ぱー"} and asJanken is {"ちょき"} then display dialog "わたしの手は" & asJanken & "でした。あなたの負けです。" else if myJanken is {"ぐー"} and asJanken is {"ぱー"} then display dialog "わたしの手は" & asJanken & "でした。あなたの負けです。" else if myJanken is {"ちょき"} and asJanken is {"ぐー"} then display dialog "わたしの手は" & asJanken & "でした。あなたの負けです。" end ifさてこのスクリプトには欠点がいくつもあります。まず「さいしょはぐー」の部分ですが「ぐー」を出さなくてもじゃんけんに進めます。「ぐー」をださない限り進めなくしたいものです。
repeat set AAA to choose from list {"ぐー", "ちょき", "ぱー"} ¬ with prompt "さいしょはぐー!" if AAA is not {"ぐー"} then--ぐーでなければ display dialog "最初はぐーだよ"--ダイアログを出す else--そうでなければ(ぐーなら) exit repeat--repeatを抜ける end if end repeat上のようにrepeatを入れぐーならばrepeatを抜けれるようにすれば「さいしょはぐー」の部分は完成です。 次の欠点は勝っても負けてもあいこでもじゃんけんが終了してしまう事です。こちらもrepeat文で直す事が出来ます。
repeat set AAA to choose from list {"ぐー", "ちょき", "ぱー"} with prompt "じゃんけん" set myJanken to AAA set BBB to random number from 1 to 3 if BBB is 1 then set asJanken to {"ぐー"} else if BBB is 2 then set asJanken to {"ちょき"} else set asJanken to {"ぱー"} end if if myJanken is asJanken then display dialog "あいこだよ" else if myJanken is {"ぱー"} and asJanken is {"ぐー"} then display dialog "わたしの手は" & asJanken & "でした。あなたの勝ちです。" exit repeat else if myJanken is {"ぐー"} and asJanken is {"ちょき"} then display dialog "わたしの手は" & asJanken & "でした。あなたの勝ちです。" exit repeat else if myJanken is {"ちょき"} and asJanken is {"ぱー"} then display dialog "わたしの手は" & asJanken & "でした。あなたの勝ちです。" exit repeat else if myJanken is {"ぱー"} and asJanken is {"ちょき"} then display dialog "わたしの手は" & asJanken & "でした。あなたの負けです。" exit repeat else if myJanken is {"ぐー"} and asJanken is {"ぱー"} then display dialog "わたしの手は" & asJanken & "でした。あなたの負けです。" exit repeat else if myJanken is {"ちょき"} and asJanken is {"ぐー"} then display dialog "わたしの手は" & asJanken & "でした。あなたの負けです。" exit repeat end if end repeatこれでいちおう完成ですが、勝ち負け判定に同じ処理を何度も書いています。こういうのはスクリプト的に非常によろしくないですし、そもそも勝ち負け判定自体もif文がいっぱいでスマートではありません。 まず勝ち負け判定ですが「あいこ」なら繰り返しでそれ以外なら勝ちか負けなので繰り返しを抜けます。そして「勝ち」かどうか判定できれば「あいこ」と「勝ち」以外は自動的に「負け」なので判定する必要はありません。これをスクリプトにすると下記のようになります。
if myJanken is asJanken then display dialog "あいこだよ" else if myJanken is {"ぱー"} and asJanken is {"ぐー"} then display dialog "わたしの手は" & asJanken & "でした。あなたの勝ちです。" else if myJanken is {"ぐー"} and asJanken is {"ちょき"} then display dialog "わたしの手は" & asJanken & "でした。あなたの勝ちです。" else if myJanken is {"ちょき"} and asJanken is {"ぱー"} then display dialog "わたしの手は" & asJanken & "でした。あなたの勝ちです。" else display dialog "わたしの手は" & asJanken & "でした。あなたの負けです。" end if exit repeat end ifこれで多少はスマートになりましたがまだまだ工夫の余地がありそうです。私がいろいろ考えたところなんとか下記のようになりました。みなさんもいろいろ工夫してみてください。
set MSGSTR to "さいしょはぐー!" repeat set asJanken to item (random number from 1 to 3) of {{"ぐー"}, {"ちょき"}, {"ぱー"}} set myJanken to choose from list {"ぐー", "ちょき", "ぱー"} with prompt MSGSTR if myJanken is {"ぐー"} and MSGSTR is "さいしょはぐー!" then set MSGSTR to "じゃーんけーんぽん!" else if MSGSTR is "さいしょはぐー!" then display dialog "さいしょはぐーだよ!" else if myJanken is asJanken then set MSGSTR to "あーいこーでしょっ!" else if {myJanken, asJanken} is {{"ぱー"}, {"ぐー"}} or ¬ {myJanken, asJanken} is {{"ぐー"}, {"ちょき"}} or ¬ {myJanken, asJanken} is {{"ちょき"}, {"ぱー"}} then set FLG to "勝ち" exit repeat else set FLG to "負け" exit repeat end if end repeat display dialog "わたしの手は" & asJanken & return & "あなたの手は" & ¬ myJanken & return & "あなたの" & FLG & "です。"
set myChar to ASCII character (34) set myNum to ASCII number "A" --ちなみに改行はreturnでタブはtabです。下記はクリップボードを操作します。コピーした文字列を取り出したり、クリップボードにテキストを入れて、ペーストすることができます。
set the clipboard to "123"--クリップボードに文字列を入れる set myTable to the clipboard--クリップボードから文字列を取り出す下記はSORTです。早くありませんが、リストを並べ替えます。
on SORT(myList) set myCount to count items of myList repeat set myFLG to false repeat with N from 1 to myCount - 1 set buf1 to item N of myList set buf2 to item (N + 1) of myList if buf1 < buf2 then set item N of myList to buf2 set item (N + 1) of myList to buf1 set myFLG to true end if end repeat if myFLG is false then exit repeat end if end repeat return myList end SORT
with timeout of 1 second--タイムアウトを1秒に設定 tell application "Adobe Illustrator" tell document 1 try--tryスタート set contents of text frame 1 to "あいうえお" on error--もしエラーがあれば下を実行 display dialog "失敗しました。" end try--try文終わり end tell end tell end timeout--タイムアウト設定ここまでタイムアウトの設定 IllustratorやInDesignなどは連続してAppleScriptを送信しつづけるとだんだん遅くなったりEPSを配置する時に「配置できません」とダイアログが表示されたりします。またスクリプトを送信しているのに応答しない事もしばしばあります。そういう時AppleScriptは応答待ちになってしばらく止まるのですがwith timeout of 1 secondをすると1秒だけしか待たないようになります。
with timeout of 1 second
set myStr to "あいう,かきく,さしす" set OriginalDelimiters to AppleScript's text item delimiters --元々の区切り文字を保存しておく。決まり事として必ず使う set findStr to "," --検索文字set repStr to "%" --置換文字 set AppleScript's text item delimiters to {findStr}--区切り文字を","にする set myStr to text items of myStr--","区切りでリストにする set AppleScript's text item delimiters to {repStr}--区切り文字を"%"にする set myStr to myStr as string--"%"区切りでテキストにする set AppleScript's text item delimiters to OriginalDelimiters --もともとの区切り文字に戻しておく。これも決まり事。 display dialog myStr =>あいう%かきく%さしす検索置換のハンドラ(関数)replaceAllです。これをスクリプトの一部に書いておいてset myStr to my replaceAll("元の文字", "検索文字", "置換文字")とすれば検索置換できます。大量に検索置換すると(もしくは特定の文字があると)文字化けする時があります。
set myStr to "あいう,かきく,さしす" set myStr to my replaceAll(myStr, ",", "%") display dialog myStr on replaceAll(motoStr, findStr, repStr) set OriginalDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to {findStr} set motoStr to text items of motoStr set AppleScript's text item delimiters to {repStr} set motoStr to motoStr as string set AppleScript's text item delimiters to OriginalDelimiters return motoStr end replaceAll下記ハンドラでset myCount to my countFields("元の文字", "区切り文字")で変数myCountには元の文字を 区切り文字で分割した数が入ります。 set myStr to my nthFields("元の文字", "区切り文字", アイテム数)で元の文字を 区切り文字で分割した2つめ等を取り出せます。
set myStr to "あいう,かきく,さしす" set myCount to my countFields(myStr, ",") set myStr to my nthFields(myStr, ",", 2) display dialog "合計" & (myCount as string) & "個で2つめは:" & myStr on countFields(myStr, sep) set OriginalDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to {sep} set myStr to text items of myStr return count myStr end countFields on nthFields(myStr, sep, num) set OriginalDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to {sep} set myStr to text items of myStr set AppleScript's text item delimiters to OriginalDelimiters return item num of myStr end nthFields
set myFile to choose file with prompt "ファイルを選択" open for access myFile--ファイルを開く set myStr to read myFile--読み込み結果を変数myStrに入れる close access myFile--ファイルを閉じる display dialog myStr上とほとんど同じなのですが as list using delimiter {return}を付けるとtextではなく改行区切りのlistで読み込みます。1行づつ処理したい場合は便利です。
set myFile to choose file with prompt "ファイルを選択" open for access myFile set myList to read myFile as list using delimiter {return} close access myFile display dialog item 1 of myList改行コードがcrのShiftJISなら下記1行づつ処理。 set textPath to "Macintosh HD:test.txt" set fobj to open for access alias textPath read fobj set str_data to result close access fobj set OriginalDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to {return} set str_data to text items of str_data repeat with L from 1 to count str_data display dialog "#" & item L of str_data & "#" end repeat set AppleScript's text item delimiters to OriginalDelimiters crlfは set AppleScript's text item delimiters to {(ASCII character (13)) & (ASCII character (10))} ifは set AppleScript's text item delimiters to {ASCII character (10)} です。 UTF16なら as Unicode textをつけます。 set textPath to "Macintosh HD:testutf16cr.txt" set fobj to open for access alias textPath read fobj as Unicode text set str_data to result close access fobj
set newFile to choose file name display dialog newFile as string作成したファイルに書き込むには下記を使います。
set newFile to choose file name set file_h to open for access newFile with write permission set eof file_h to 0 write "こんにちは" to file_h--書き込む close access file_h--ファイルを閉じる
set myFol to choose folder with prompt "フォルダを選択" set myFol to myFol as string--フォルダのフルパス repeat with myFile in list folder myFol without invisibles--フォルダ内リピート set this_item to (myFol & myFile) as alias--フォルダとファイル名を合体 set Fpath to this_item as string--フルパスを取り出す display dialog Fpath end repeat下記はフォルダ内のフォルダも含めて繰り返します。
set myFol to choose folder with prompt "フォルダを選択" my folderLoop(myFol)--オリジナル関数folderLoopを呼び出す on folderLoop(myFol) set myFol to myFol as string repeat with myFile in list folder myFol without invisibles set this_item to (myFol & myFile) as alias set myInfo to info for this_item if folder of myInfo is true then my folderLoop(this_item)--自分自身を呼び出す else set Fpath to this_item as string display dialog Fpath end if end repeat end folderLoop
set this_item to choose file with prompt "配置ファイルを選択" set Fpath to this_item as string--ファイルのフルパスをテキスト形式で取り出す display dialog Fpath--表示する。下記ではファイルタイプが"EPSF"か"EPSP"かまたは種類が"EPS ファイル"のファイルだけ処理関数に渡すといったちょっと気の利いた事をしています。下記では処理関数setEPS2を呼び出しています。
set this_item to choose file with prompt "配置ファイルを選択" set Fpath to this_item as string--ファイルのフルパスをテキスト形式で取り出す set Finfo to info for this_item--ファイルインフォメーションを取り出す set FType to file type of Finfo --ファイルインフォメーションからファイルタイプを取り出す set Fkind to kind of Finfo--ファイルインフォメーションから種類を取り出す if FType is "EPSF" or FType is "EPSP" or Fkind is "EPS ファイル" then my setEPS2(this_item, Fpath)--処理をする。 end if
display dialog "こんにちは" --キャンセルをクッリクすると処理終了
set myAnswer to display dialog "入力してください" default answer "ここに入力" set inputStr to text returned of myAnswer display dialog "入力したのは「" & inputStr & "」ですね"
set myAnswer to display dialog "食べたいものは" buttons {"くり", "こめ", "つけもの"} set selectedBtn to button returned of myAnswer display dialog "クリックしたのは「" & selectedBtn & "」ですね"
set myAnswer to display dialog "ページ数" default answer "1" buttons {"縦組", "横組"} set inputStr to text returned of myAnswer set selectedBtn to button returned of myAnswer display dialog "ページ数が" & inputStr & "ページで" & selectedBtn & "ですね"
set mySelect to choose from list {"りんご", "みかん", "ぶどう"} with prompt ¬ "選択してください"--¬は実際には改行を入れない display dialog item 1 of mySelect--listで返ってくるのでitem 1 で取り出す。
set mySelectList to choose from list {"りんご", "みかん", "ぶどう"} with prompt ¬ "選択してください" with multiple selections allowed --複数選択可 repeat with mySelect in mySelectList --listの中のitem分繰り返す display dialog mySelect end repeat
set AAA to 10 set myStr to "変数AAAの内容は" & AAA & "です。" =>"変数AAAの内容は10です。"比較演算子などif文の中に書き込む内容です。
set AAA to 10 if AAA > 5 then display dialog "変数AAAは5より小さい" end if if AAA is 10 then display dialog "変数AAAは10" end if if AAA is not 5 then display dialog "変数AAAは5以外" end if if AAA is in {9, 10, 11} then display dialog "変数AAAは9,10,11に含まれる" end if
足し算、引き算、かけ算、割り算。基本はこれだけです。あとできれば割っ たあまりと割ったあまりを除いた整数部分が取り出せると便利です。
set X to A+1--変数Xに変数A+1を入れる set X to X-1--変数Xに変数A-1を入れる set X to N*5--変数Xに変数N×5を入れる set X to N/2--変数Xに変数N÷2を入れる set X to 5 mod 2--=>1になる。割ったあまり。 set X to 5 div 2--=>5になる。割ってあまりを除いた整数部分
割ったあまりをだすmodを使って偶数か奇数かを調べることが出来ます。
if N mod 2 = 1 then--もし変数Nを2で割ったあまりが1なら display dialog "変数Nは奇数です。" else--そうでないなら display dialog "変数Nは偶数です。" end if
これが最低限ですが、これだけでScriptを書くには十分です。
display dialog AAA上のように命令があってその後にパラメータが入ります。ほかにもいろい ろなパラメータやオプションパラメータなどたくさんの文字が続くことも多 いです。さらに値を返すコマンドもあります。AdobeやQuarkXPress共通で なにかを作りたいときにmakeというコマンドを作ります。
make text frameというように書くのですが
set myObj to make text frameとすると作られたオブジェクトが変数myObjに入ります。 **ハンドラ(関数)** Round()は数字をまるめる関数です。関数には()←カッコがついていてカッ コの中には値を入れます。
set BBB to Round(10.5)自分でハンドラ(関数)を作る事も出来ます。
my Disp("あいうえお") --自分で作った関数Dispを呼び出す。myが必要なので注意 on Disp(AAA) --自分が作った関数Dispカッコの中の変数に渡された値が入る。 display dialog AAA & "です。" end Disp
repeat with CCC from 1 To 10 display dialog CCC end repeat =>結果は1から10までの文字がダイアログで発生する。くりかえし2 無限に繰り返す処理を入れある条件が成立したら処理を終わります。
set DDD to 1--変数DDDに1を入れる。 repeat--無限に繰り返す。 if DDD > 50 then--もし変数DDDが50以上なら exit repeat--繰り返しを抜ける end if set DDD to DDD + 1--変数DDDに1をプラスする。 end repeatくりかえし3 配列変数のなかを1つづつ変数に入れます。
set meishiFile to {"たけうち", "森田", "おおもり", "ばば", "なかむら"} as list repeat with myName in meishiFile --↑配列変数meishiFileの中を1つづつ順に変数myNameに入れる display dialog myName & "さん" end repeat =>「たけうちさん」「森田さん」「おおもりさん」。。。と順に表示される
set AAA to "あいうえお" if AAA is "あいうえお" then --もしAAAが"あいうえお"なら display dialog "あいうえおです。" end if「もし〜ではなかったら」の場合は下記のように書きます。
set AAA to "あいうえお" if AAA is not "あいうえお" then --もしAAAが"あいうえお"ではなかったら display dialog "あいうえおではありません。" end if「もしも〜なら」と「そうではなくて〜なら」と「それ以外なら」という ように条件によって振り分ける場合は下のように書きます。
set AAA to "あいうえお" if AAA is in "あいう" then --もしAAAが"あいうえお"に含まれるなら display dialog "あいうえおです。" else if AAA is "かきくけこ" then --もしAAAが"かきくけこ"なら display dialog "かきくけこです。" else--それ以外なら display dialog "それ以外です。" end if「もしも〜でさらに〜なら」と「もしも〜または〜なら」というように2つ の条件によって振り分ける場合は下のように書きます。
set AAA to 10 if 0 < AAA and AAA < 20 then--andの入ったif文 display dialog "変数AAAは0より大きく20より小さい" end if if 0 > AAA or AAA > 20 then--orの入ったif文 display dialog "変数AAAは0より小さいまたは20より大きい" end if以上のようにif文はかなり簡単ですがif文そのものよりもどこでif文を使う かという考え方のほうが理解しにくいのかもしれません。
set meishiFile to {"たけうち","森田","おおもり","ばば","なかむら"} as list display dialog item 5 of meishiFile & "さん" =>"なかむらさん"というようになります。このlist変数がわかりにくいのですが例えば Illustratorで選択したアイテムを調べると選択アイテムは1つとは限らないの で複数のlistで値が帰ってきます。そこから選択アイテムの1つめといったよ うに取り出します。とにかく非常によく出てくるしlistを使わないと AppleScriptは書けないので、がんばって理解してください。
set myStr to "こんにちは。"--変数myStrに"こんにちは。"を入れる display dialog myStr--変数myStrをダイアログに表示もちろん変数ですから数字も入れることができます。
set Y to 1--変数Yに1を入れる set X to 5--変数Xに5を入れる display dialog Y+X--変数Y+Xの結果をダイアログに表示※--はコメントで、プログラムでは--以降の文字は無視されます。 **変数の種類と変数の型変換**
set X to 1.5258--変数Xに1.5258を入れる set X to X as integer--変数Xを型変換する display dialog X--変数Xをダイアログに表示 =>2変数1.5258を整数に型変換したため結果は2になりました。
set myNum to 1 set myStr to myNum as string上の例は変数myNumを文字列に変換してmyStrに入れます。人間の見た 目には整数の1も文字列の"1"もあまり変わりませんが、AppleScriptからDTP アプリケーションをコントロールするときなど良く使いわけます。
display dialog "こんにちは! "ウィンドウ上部の実行ボタンをクリックしてください。"こんにちは! "と ダイアログが現れたら大成功です。次はIllustratorを起動してください。ド キュメントを作成してテキストオブジェクトを作り、適当に文字を入力して おいてください。スクリプト編集プログラムに下記を入力して実行します。
tell application "Adobe Illustrator" tell document 1 set contents of text frame 1 to "こんにちは! " end tell end tellIllustratorのテキストが"こんにちは! "になれば成功です。"Adobe Illustrator"を"Adobe InDesign CS2_J"に変えても動きます。 ※実行ボタンをクリックするとInDesignはどこにあるか聞いてくるかもしれ ません。その場合アプリケーションフォルダの中から選択してください。 どうでしょう。簡単なスクリプトですが大きな可能性に気がつくと思いま す。このスクリプトを応用してやるとクライアントからもらったEXCELの原 稿をつぎつぎにIllustratorに流し込む事ができます。簡単ではないですが AppleScriptが使えるようになれば現場で大きな効率化をはたすことができ ます。ぜひチャレンジしてみてください。
on adding folder items to this_folder after receiving added_items try tell application "Finder" --↓フォルダアクションの設定されているフォルダ set the folder_name to the name of this_folder end tell --set the item_count to the number of items in the added_items --↓フォルダにドロップされたファイル repeat with myFile in added_items tell application "Finder" set the file_name to the name of myFile end tell display dialog folder_name & "内の" & file_name end repeat end try end adding folder items to
作成したスクリプトは Library=>Scripts=>Folder Action Scripts に入れておく スクリプトメニューから Folder Actions=>Attach Script to Folder を選ぶ 使用するスクリプトを選ぶ フォルダアクションを設定したいフォルダを選ぶ
delay 5
with timeout of 1 second 処理 end timeout
tell application "Finder" set OriginalDelimiters to AppleScript's text item delimiters --現在のdelimiters設定を保存しておく。 set AppleScript's text item delimiters to {tab} set PROSESS_LIST to (name of every application process) set TexData to PROSESS_LIST as string --すべての起動しているアプリケーションのリストをPROSESS_LISTへ set AppleScript's text item delimiters to OriginalDelimiters --必ずdelimiters設定を戻しておく。 --display dialog TexData end tell
set downFolder to choose folder with prompt "収集するフォルダを選択してください。" tell application "Finder" duplicate alias "Macintosh HD:gazou:PAK2:001111" to downFolder with replacing end tell with replacingで上書きコピー with replacingをつけないと上書きコピーされない 同じ名前のファイルがあるとエラーでストップ
Applications =>AppleScript =>Install Script Menu をダブルクリックする。
on run set curItem to choose folder with prompt "フォルダを選択" my chmod777(curItem) end run on open theList repeat with curItem in theList my chmod777(curItem) end repeat end open on chmod777(curItem) set myPath to POSIX path of curItem set cmdStr to "chmod -R 777 " & myPath do shell script cmdStr end chmod777
on open inputList tell application "Finder" repeat with inputFile in inputList set comment of inputFile to name of inputFile end repeat end tell end open
on open inputList tell application "Finder" repeat with inputFile in inputList my getMyFolder(inputFile) end repeat end tell end open on run set myFolder to choose file with prompt "ファイルを選択してください" my getMyFolder(myFolder) end run on getMyFolder(myFolder) tell application "Finder" set creator type of myFolder to "ART5" --"YoED" --set file type of myFolder to "TEXT" --"YoED" end tell end getMyFolder --★Illustrator --set creator type of myFolder to "ART5" --set file type of myFolder to "TEXT" --★QXP --set creator type of myFolder to "XPRa" --set file type of myFolder to "XDOC" --★mi --set creator type of myFolder to "MMKE" --set file type of myFolder to "TEXT" --★Excel --set creator type of myFolder to "XCEL" --set file type of myFolder to "XLS8" --★Word --set creator type of myFolder to "MSWD" --set file type of myFolder to "W8BN" --★REALbasic --set creator type of myFolder to "RBv2" --set file type of myFolder to "RbBF" --★Application --set file type of myFolder to "APPL"
set the clipboard to "123" set myTable to the clipboard
on nthFields(myStr, sep, num) set OriginalDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to {sep} set myStr to text items of myStr set AppleScript's text item delimiters to OriginalDelimiters return item num of myStr end nthFields myStrをsep区切りでnum番目の項目を返す
set OriginalDelimiters to AppleScript's text item delimiters set KEN to return --検索文字 set TIKAN to "" --置換文字 set AppleScript's text item delimiters to {KEN} set TexData to text items of TexData set AppleScript's text item delimiters to {TIKAN} set TexData to TexData as string set AppleScript's text item delimiters to OriginalDelimiters on replaceAll(motoStr, FindStr, repStr) set OriginalDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to {FindStr} set motoStr to text items of motoStr set AppleScript's text item delimiters to {repStr} set motoStr to motoStr as string set AppleScript's text item delimiters to OriginalDelimiters return motoStr end replaceAll
on countFields(myStr, sep) set OriginalDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to {sep} set myStr to text items of myStr return count myStr end countFields myStrをsep区切りで項目数を返す
on SORT(myList)
set myCount to count items of myList
repeat
set myFLG to false
repeat with N from 1 to myCount - 1
set buf1 to item N of myList
set buf2 to item (N + 1) of myList
if buf1 < buf2 then
set item N of myList to buf2
set item (N + 1) of myList to buf1
set myFLG to true
end if
end repeat
if myFLG is false then
exit repeat
end if
end repeat
return myList
end SORT
open for access file FileName read file FileName set TexData to result close access file FileNam
open for access file FileName with write permission write TexData to file FileName close access file FileName
ASCII character (10)
ASCII number "A"