[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
(DTPtechNote:1391) [AS_Indesign CS2]Save Package 0.2
こちらもIndesign CS2用に若干書き直し。
パッケージコマンドでは、「including hidden layers」は省略できなくなったみたい。
不具合など、お気づきの点がありましたら、お気軽にお知らせください。
#わたしは怠け者なので、連絡ないと直したりしません^^
よろしくお願いいたします。
on open of theFiles
set {save_folder, pdf_export_presets} to my preparation() --前準備
--ファイルのフィルタリング
set my_files to my file_kind({"ind", "indd"}, {"IDd4"}, theFiles)
--ファイルを開いて、コントロールルーチンへ
repeat with i in my_files
tell application "Adobe InDesign CS2_J"
set user interaction level of script preferences to never interact --ユーザー操作を禁止します
try
open i
on error errMsg number errNum
set user interaction level of script preferences to interact with all --ユーザー操作の再開
my my_error("誤りが起きました;" & i & return & "処理を中断しますか?" & return & errMsg & return & errNum, false)
end try
set user interaction level of script preferences to interact with all --ユーザー操作の再開
set doc_name to (name of document 1) as Unicode text
set doc_name to do shell script "echo '" & doc_name & "' | sed -e 's/??.indd$//;'"
--set doc_name to my as_replace(doc_name, ".indd", "")
my control_routin(save_folder, doc_name, pdf_export_presets)
close document 1 saving no
end tell
end repeat
----終了の合図
say "Work was finished. " & (length of my_files) & " files were processed."
end open
on run
set {save_folder, pdf_export_presets} to my preparation() --前準備
my doc_exists()
tell application "Adobe InDesign CS2_J"
set doc_name to (name of document 1) as Unicode text
set doc_name to do shell script "echo '" & doc_name & "' | sed -e 's/??.indd$//;'"
end tell
my control_routin(save_folder, doc_name, pdf_export_presets)
--終了の合図
say "Work was finished. "
end run
--------------------------------------------------------○準備
to preparation()
my ver()
set save_folder to my choose_folder()
set pdf_f to button returned of (display dialog ("パッケージフォルダにPDFを作成しますか?" as Unicode text) buttons {"キャンセル", "パッケージのみ", "作成"} default button 3 with icon 1)
if pdf_f = "作成" then
--書き出しPDFスタイルを選択する
set pdf_export_presets to my pdf_style()
else
set pdf_export_presets to false --PDFを作らないときはpdf_export_presetsがfalse
end if
return {save_folder, pdf_export_presets}
end preparation
--------------------------------------------------------●コントロールルーチン
to control_routin(save_folder, doc_name, pdf_export_presets)
set save_PDF_path to save_folder & doc_name & ":" & doc_name & ".pdf"
tell application "Finder"
try
set save_folder to make new folder at save_folder with properties {name:doc_name}
on error errMsg number errNum
my my_error("誤りが起きました(make new Folder);" & save_PDF_path & return & "処理を中断しますか?" & return & errMsg & return & errNum, false)
return
end try
end tell
try
my save_Package(save_folder as Unicode text, false)
if pdf_export_presets is not false then my save_PDF(save_PDF_path, pdf_export_presets)
on error errMsg number errNum
my my_error("誤りが起きました(Package or PDF);" & save_PDF_path & return & "処理を中断しますか?" & return & errMsg & return & errNum, false)
end try
end control_routin
--------------------------------------------------------●InDesignバージョン確認ルーチン
to ver()
tell application "Adobe InDesign CS2_J"
set my_version to (version of script preferences) as real
if my_version < 4 or my_version > 4.9 then
activate
my my_error("このプログラムはInDesign CS2以外では動作しません", true)
end if
my_version
end tell
end ver
--------------------------------------------------------●パッケージのフォルダを保存するフォルダを選択
to choose_folder()
set save_folder to choose folder with prompt ("パッケージのフォルダを保存するフォルダを選択してください" as Unicode text)
return (save_folder as Unicode text)
end choose_folder
--------------------------------------------------------●書き出しPDFスタイルを選択する
to pdf_style()
tell application "Adobe InDesign CS2_J"
set pdf_export_presets to name of PDF export presets
set pdf_export_presets to choose from list pdf_export_presets with prompt ("PDF書き出しプリセットを選んでください") as Unicode text
end tell
if pdf_export_presets = false then my my_error("処理を中止します", true)
return pdf_export_presets as Unicode text
end pdf_style
--------------------------------------------------------●ドキュメントが開かれているかどうか
to doc_exists()
tell application "Adobe InDesign CS2_J"
if not (exists document 1) then
activate
my my_error("ドキュメントが開かれていません", true)
end if
end tell
end doc_exists
----------------------------------------------●必要なファイルだけをフィルタして返します
to file_kind(extention_list, type_list, theFiles)
set my_files to {}
set extention_list to my conv_unicode(extention_list)
set type_list to my conv_unicode(type_list)
ignoring case
tell application "Finder"
repeat with i in theFiles
if extention_list contains ((name extension of i) as Unicode text) then
set end of my_files to contents of i
else if (kind of i) is "フォルダ" as Unicode text then
--activate
--display dialog "フォルダ「" & (name of i) & "」の中の全ファイルを処理します" buttons {"キャンセル", "OK"} default button 2 with icon 0
set my_files to my_files & my file_kind(extention_list, type_list, every file in folder i)
else if type_list contains ((file type of i) as Unicode text) then
set end of my_files to contents of i
else
--activate
--display dialog "ファイル「" & (name of i) & "」は処理ファイルとして不適当です" buttons {"キャンセル", "OK"} default button 2 with icon 0
end if
end repeat
end tell
end ignoring
return my_files
end file_kind
--------------------------------------------------------●パッケージをsaveする
to save_Package(save_folder, preflight_errors)
set save_folder to save_folder as string --濁音、半濁音のための苦肉な処理
set save_folder to save_folder as Unicode text
tell application "Adobe InDesign CS2_J"
set succeeded to package document 1 to save_folder ignore preflight errors preflight_errors with copying fonts, copying linked graphics, copying profiles, including hidden layers, updating graphics and creating report
if succeeded is false then
set ANS to button returned of (display dialog (save_folder & "はプリフライトエラーです。続行しますか?" as Unicode text) buttons {"キャンセル", "パスする", "パッケージ"} with icon 0)
if ANS is "パッケージ" then my save_Package(save_folder, true)
end if
end tell
end save_Package
--------------------------------------------------------●PDFをsaveする
to save_PDF(save_PDF_path, pdf_export_presets)
tell application "Adobe InDesign CS2_J"
set page range of PDF export preferences to all pages --すべてのページを書き出す
with timeout of 3600 seconds
export document 1 format PDF type to save_PDF_path using PDF export preset pdf_export_presets
end timeout
end tell
end save_PDF
----------------------------------●置換
to as_replace(theText, orgStr, newStr)
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to orgStr
set tmpList to every text item of theText
set AppleScript's text item delimiters to newStr
set tmpStr to tmpList as text
set AppleScript's text item delimiters to oldDelim
return tmpStr
end as_replace
----------------------------------●リストの項目をunicode textにする
to conv_unicode(tmp_list)
repeat with i in tmp_list
set contents of i to (contents of i) as Unicode text
end repeat
return tmp_list
end conv_unicode
----------------------------------●エラー処理
on my_error(err_str, my_stop)
set err_str to err_str as Unicode text
if my_stop then
set my_stop to {"中止"}
else
set my_stop to {"中止", "続行"}
end if
tell application "Adobe InDesign CS2_J"
activate
beep
set ANS to button returned of (display dialog err_str buttons my_stop with icon 0) --警告ダイアログ出してストップ
if ANS is "中止" then error number -128
end tell
end my_error