●メニューへ ●単福へ ●自動車の維持費をシミュレーション ●InDesign JavaScript ノート

Document/見開きか単ページか


		tell application "Adobe InDesign CS2_J"
			tell active document
				tell document preferences
					set myBool to facing pages --false:単ページ,true:見開き
				end tell
			end tell
		end tell


TOPへ


master/masterページアイテムを上書きする


tell application "InDesign CS_J"
	tell document 1
		override item 1 of master page items of page 1 destination page page 1
	end tell
end tell


TOPへ


text frames/ルビ


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


TOPへ


text frames/字取り変更


Iビームカーソルでテキストを選択し、今9字取りの文字列を7字取りに変更と言ったことができるスクリプト

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 myStrend nthFields


TOPへ


text frames/縦組にする


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



TOPへ


サンプル/EPSをページに配置


--変数myPerの値を100にしておく(拡大率100%)
set myPer to 100
--変数NURIの値を3にしておく(ぬりたし3mm)
set NURI to 3 --塗り足し(0にすると塗り足しなし)

--フォルダ選択ダイアログを出し結果を変数myFolに入れる
set myFol to choose folder with prompt "フォルダを選択"
--変数myFolのフルパスを取り出す
set myFol to myFol as string
--変数myPageの値を1にする(スタートページ)
set myPage to 1

--フィルダ内のファイル分繰り返す
repeat with myFile in list folder myFol without invisibles
	--処理するファイルを変数this_itemにいれる
	set this_item to (myFol & myFile) as alias
	--変数this_itemの情報からファイルタイプを変数FTypeにいれる
	set FType to file type of (info for this_item)
	--もし変数FTypeが"EPSF"なら
	if FType is "EPSF" then
		--オリジナル関数setEPSを呼び出す(変数myPage、変数myFolとmyFileがくっついたもの、 変数NURI、変数myPerを渡す)
		my setEPS(myPage, myFol & myFile, NURI, myPer)
		--変数myPageに1を足す
		set myPage to myPage + 1
	end if
end repeat

--オリジナル関数setEPSの宣言
on setEPS(myPage, inputFile, NURI, myPer)
	--ここより下でend tryより上を試す(エラーが出ても止まらないようにするため)
	try
		--"Adobe InDesign CS2_J"を呼ぶ
		tell application "Adobe InDesign CS2_J"
			--"最前面のドキュメント"を呼ぶ
			tell active document
				--もし変数myPageのページが存在しないなら
				if not (exists of page myPage) then
					--最後にページをつくる
					make page at end
				end if
				--ページの領域を変数myBに入れる{Y1,X1,Y2,X2}で返ってくる
				set myB to bounds of page myPage
				--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 (myPage)
					--画像ボックスを作り変数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 EPSobj to place inputFile on myRect
					--EPSobjを呼ぶ
					tell EPSobj
						--水平方向の比率と垂直方向の比率を変数myPerにする
						set properties to {vertical scale:myPer, horizontal scale:myPer}
					end tell
					--myRectにセンター揃えの命令を送る
					fit myRect given center content
				end tell
			end tell
		end tell
	end try
end setEPS




TOPへ


サンプル/PDFをページに配置


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


TOPへ


サンプル/PDF書き出し


--開いているドキュメントを全部PDF書き出し
--Macintosh HDにPDFフォルダを作っておく

tell application "Adobe InDesign CS2_J"
	set Dcount to count document
	repeat with D from 1 to Dcount
		set Fname to name of document D
		set Fpath to "Macintosh HD:PDF:" & Fname & ".pdf"
		--export document D format PDF type to Fpath using PDF export preset 15
		export document D format PDF type to Fpath using PDF export preset "[PDF/X-1a:2001 (日本)]"
	end repeat
end tell


TOPへ


配置画像/フレームにfit等


tell application "Adobe InDesign CS2_J"
	tell active document
		fit rectangle 1 given content to frame
		--proportionally
		--content to frame/内容をフレームにあわせる
		--center content/内容を中央に
		--proportionally/短辺合わせ
		--frame to content/フレームをあわせる
		--fill proportionally/長辺合わせ
	end tell
end tell


TOPへ


表/テキストを表にペースト


クリップボードのテキストを
InDesignCSの表の選択部分にペーストします。


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


TOPへ


表/選択された表を調べる


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


TOPへ