InDesign で PDFとパッケージフォルダを書き出しZIP圧縮し、元ファイルをリネームする
当然もっとエレガントな書き方があるんだろうけど。
--1-PDF見開きのみ
try
tell application "Adobe InDesign CS4"
save document 1
set org_name to (name of document 1) as Unicode text
set doc_name to do shell script "echo '" & org_name & "' | sed -e 's/\\.indd$//;'"
--↑拡張子の削除
set PDF_doc to doc_name & ".pdf"
set Fpath to "snoopy:users:pinkman:Desktop:" & PDF_doc

tell application "Finder"
if exists file PDF_doc of desktop then
delete file PDF_doc of desktop
end if
end tell

export document 1 format PDF type to Fpath using PDF export preset "nobidouble"
save document 1
close document 1
end tell --tell application "Adobe InDesign CS4"
tell application "Preview"
activate
tell application "System Events"
key code 13 using {command down} --W
end tell
end tell
on error
tell application "Finder"
activate
display dialog "エラーです"
end tell
beep 2
end try
--2-パッケージまですべて
try
tell application "Adobe InDesign CS4"
save document 1
set org_name to (name of document 1) as Unicode text
set doc_name to do shell script "echo '" & org_name & "' | sed -e 's/\\.indd$//;'"
--↑拡張子の削除
set doc_name_zip to doc_name & ".zip"
set PDF_doc to doc_name & ".pdf"
set PDF_doc_1p to "1p_" & doc_name & ".pdf"

set Fpath to "snoopy:users:pinkman:Desktop:" & PDF_doc
set Fpath_1p to "snoopy:users:pinkman:Desktop:" & PDF_doc_1p

tell application "Finder"
if exists file PDF_doc of desktop then
delete file PDF_doc of desktop
end if
if exists file PDF_doc_1p of desktop then
delete file PDF_doc_1p of desktop
end if
if exists folder doc_name of desktop then
delete folder doc_name of desktop
end if
if exists folder "zxc_vbnm%x" of desktop then
delete folder "zxc_vbnm%x" of desktop
end if
end tell
tell application "Finder"
try
delete file doc_name_zip of desktop
end try
end tell
--zipファイルはあえて捨てなくとも内容が置き換えられてしまう模様。
--でもそれだと追加日でソートできないのでやっぱり捨てる。何故か下記では機能しない。
--else if exists file doc_name_zip of desktop then
--delete file doc_name_zip of desktop

export document 1 format PDF type to Fpath using PDF export preset "nobidouble"
beep
export document 1 format PDF type to Fpath_1p using PDF export preset "nobisingle"

--▼★★★パッケージしてフォルダ名を doc_name に変更して圧縮
tell application "Finder"
try
(*「デスクトップ」フォルダがすでに開いている場合に備えて*)
select Finder window "デスクトップ"
set toolbar visible of Finder window 1 to true
set current view of Finder window 1 to list view
set visible of column id modification date column of list view options of Finder window 1 to true --変更日
set sort column of list view options of Finder window 1 to modification date column
on error
(*「デスクトップ」ウィンドウが存在しない場合*)
set xdr5 to ((path to home folder) as text) as alias
make new Finder window to folder "Desktop" of folder xdr5
set toolbar visible of Finder window 1 to true
set current view of Finder window 1 to list view
set visible of column id modification date column of list view options of Finder window 1 to true --変更日
set sort column of list view options of Finder window 1 to modification date column
--デスクトップウィンドウは必ずリスト表示(というかコラム表示以外)にしておく。
--圧縮セクションに「set fol_Path to (target of window 1) as alias」という行があり、
--コラム表示だとzipが「zxc_vbnm%x」の中に作られてしまう。
end try
make new folder at desktop with properties {name:"zxc_vbnm%x"}
end tell
tell application "Preview"
activate
tell application "System Events"
key code 13 using {command down} --W
delay 0.2
key code 13 using {command down} --W
end tell
end tell
--↓パッケージ
tell application "Adobe InDesign CS4"
tell document 1
set myFolder to "snoopy:Users:pinkman:Desktop:zxc_vbnm%x:"
set myResult to package to myFolder with copying profiles, copying fonts, copying linked graphics, including hidden layers, creating report, updating graphics and ignore preflight errors
end tell
end tell
--↑パッケージ終わり

tell application "Finder"
activate
select Finder window "デスクトップ"
select folder "zxc_vbnm%x" of window 1
set tmp to selection
set name of item 1 of tmp to doc_name
--↑フォルダ名を doc_name に

--↓圧縮
set i to 0
set fol_Path to (target of window 1) as alias
repeat with select_item in (selection as list)
set file_path to select_item as alias
set fil_name to name of file_path as text
set source to quoted form of POSIX path of (file_path as text)
set dest to quoted form of POSIX path of (fol_Path & fil_name & ".zip" as text)
do shell script "ditto -ck " & source & " " & dest
delay 1
set i to i + 1
end repeat
--↑圧縮終わり
--[AppleScript] Finderで複数選択している項目を1つずつzipで圧縮 | How2すいとー
--http://www.hw2-suito.com/archives/410
end tell
--▲★★★パッケージしてフォルダ名を doc_name にして圧縮
save document 1
close document 1
end tell --tell application "Adobe InDesign CS4"
tell application "Finder"
--↓元のInDesignファイル名アタマに「XXX」を付加
set addStr to "XXX"
if exists file org_name of window 1 then
select window 1
select file org_name of window 1
try
set FinderSelection to selection as alias list
on error
set FinderSelection to selection
end try
repeat with aFile in FinderSelection
set oldName to name of aFile
set newName to addStr & oldName
set name of aFile to newName
end repeat
else if exists file org_name of window 2 then
select window 2
select file org_name of window 1
try
set FinderSelection to selection as alias list
on error
set FinderSelection to selection
end try
repeat with aFile in FinderSelection
set oldName to name of aFile
set newName to addStr & oldName
set name of aFile to newName
end repeat
else if exists file org_name of window 3 then
select window 3
select file org_name of window 1
try
set FinderSelection to selection as alias list
on error
set FinderSelection to selection
end try
repeat with aFile in FinderSelection
set oldName to name of aFile
set newName to addStr & oldName
set name of aFile to newName
end repeat
else if exists file org_name of window 4 then
select window 4
select file org_name of window 1
try
set FinderSelection to selection as alias list
on error
set FinderSelection to selection
end try
repeat with aFile in FinderSelection
set oldName to name of aFile
set newName to addStr & oldName
set name of aFile to newName
end repeat
else if exists file org_name of window 5 then
select window 5
select file org_name of window 1
try
set FinderSelection to selection as alias list
on error
set FinderSelection to selection
end try
repeat with aFile in FinderSelection
set oldName to name of aFile
set newName to addStr & oldName
set name of aFile to newName
end repeat
else if exists file org_name of window 6 then
select window 6
select file org_name of window 1
try
set FinderSelection to selection as alias list
on error
set FinderSelection to selection
end try
repeat with aFile in FinderSelection
set oldName to name of aFile
set newName to addStr & oldName
set name of aFile to newName
end repeat
else if exists file org_name of window 7 then
select window 7
select file org_name of window 1
try
set FinderSelection to selection as alias list
on error
set FinderSelection to selection
end try
repeat with aFile in FinderSelection
set oldName to name of aFile
set newName to addStr & oldName
set name of aFile to newName
end repeat
else if exists file org_name of window 8 then
select window 8
select file org_name of window 1
try
set FinderSelection to selection as alias list
on error
set FinderSelection to selection
end try
repeat with aFile in FinderSelection
set oldName to name of aFile
set newName to addStr & oldName
set name of aFile to newName
end repeat
else if exists file org_name of window 9 then
select window 9
select file org_name of window 1
try
set FinderSelection to selection as alias list
on error
set FinderSelection to selection
end try
repeat with aFile in FinderSelection
set oldName to name of aFile
set newName to addStr & oldName
set name of aFile to newName
end repeat
else if exists file org_name of window 10 then
select window 10
select file org_name of window 1
try
set FinderSelection to selection as alias list
on error
set FinderSelection to selection
end try
repeat with aFile in FinderSelection
set oldName to name of aFile
set newName to addStr & oldName
set name of aFile to newName
end repeat
else if not (exists file org_name of window 10) then
display dialog "ファイルが見つかりません" with icon caution
end if
end tell
on error
tell application "Finder"
activate
display dialog "エラーです"
end tell
beep 2
end try
以下、
3-PDFのみ両方.scpt
4-パッケージのみ.scpt
5-パッケージと見開きPDF.scpt
6-パッケージと片頁PDF.scpt
7-PDF片頁のみ.scpt
とあるけど省略。その7本を
--http://kb2.adobe.com/jp/cps/511/511636.html
--http://blog.goo.ne.jp/vallie/e/91b2448c09eeba217f82099e6715d2c9
--http://e-deep.org/iblog/C535725699/E20080108155938/index.html

tell application "Quicksilver" to activate
--Quicksilver でこのスクリプトを使うには1行目にこれが必要みたい。理由は不明。
set instruction to item 1 of (choose from list {"PDF 見開きのみ", "パッケージまですべて", "PDFのみ両方", "パッケージのみ", "パッケージと片頁PDF", "パッケージと見開きPDF", "PDF 片頁のみ", " "} default items "パッケージまですべて")

--◉1
if instruction is "PDF 見開きのみ" then
end if

--◉2
if instruction is "パッケージまですべて" then
end if

--◉3
if instruction is "PDFのみ両方" then
end if

--◉4
if instruction is "パッケージのみ" then
end if

--◉5
if instruction is "パッケージと片頁PDF" then
end if

--◉6
if instruction is "パッケージと見開きPDF" then
end if

--◉7
if instruction is "PDF 片頁のみ" then
end if
の各「if」行と「end if」行の間にコピペして完成。
[PR]
by nobiox | 2014-02-04 11:26 | ├DTP | Comments(0) |
<< AppleScript で音を鳴らす | 「a.indd」を閉じて「xx... >>