property filmBreite : 455
property filmHoehe : 560
property abstand : 3
set mm to 2.835
set ordner to choose folder
tell application "Finder"
set pdfDoks to every file of ordner whose name ends with ".pdf"
set tifDoks to every file of ordner whose name ends with ".tif"
set doks to pdfDoks & tifDoks
end tell
tell application "Adobe InDesign CC 2017"
set indd to make new document
tell indd to tell document preferences to set properties to {facing pages:false, page width:filmBreite, page height:filmHoehe}
end tell
set {x1, y1, x2, y2, z, aktInddSeiten} to {1, 1, 1, 1, 1, 1}
repeat with n in doks
if ".pdf" is (items -1 thru -4 of (n as string)) as text then
set pdfSeitenZahl to (do shell script "/usr/bin/mdls " & quoted form of POSIX path of (n as alias) & " | /usr/bin/awk '/kMDItemNumberOfPages/{print $3}'") as integer
set userLocale to user locale of (get system info)
set {dokHoehe, dokBreite} to words of (do shell script "mdls -name kMDItemPageHeight -name kMDItemPageWidth -raw '" & POSIX path of (n as alias) & "'| LC_NUMERIC=" & userLocale & " xargs -0 -I _pt awk 'BEGIN {printf \"%.1f \",_pt/(72/25.385)}'")
{dokHoehe as real, dokBreite as real}
repeat with i from 1 to pdfSeitenZahl
tell application "Adobe InDesign CC 2017" to set page number of PDF place preferences to i
set {x1, y1, x2, y2, aktInddSeiten} to my check(z, n, i, x1, y1, x2, y2, aktInddSeiten, dokBreite, dokHoehe)
end repeat
else
set {dokBreitePx, dokHoehePx} to words of (do shell script "sips -g pixelHeight -g pixelWidth " & quoted form of POSIX path of (n as alias) & " | awk '/pixel/ {print $NF}'")
set reso to words of (do shell script "sips -g dpiHeight " & quoted form of POSIX path of (n as alias) & " | awk '/dpi/ {printf \"%.0f \", $NF}'")
set resoMM to (reso as real) / 25.4
set {dokHoehe, dokBreite} to {dokBreitePx / resoMM, dokHoehePx / resoMM}
set {x1, y1, x2, y2, aktInddSeiten} to my check(z, n, i, x1, y1, x2, y2, aktInddSeiten, dokBreite, dokHoehe)
end if
set z to z + 1
end repeat
on check(z, n, i, x1, y1, x2, y2, aktInddSeiten, dokBreite, dokHoehe)
set altSeiten to aktInddSeiten
if filmBreite is greater than dokBreite and filmHoehe is greater than dokHoehe then
if z is 1 and i is 1 then
set x1 to 1
set y1 to 1
set x2 to x1 + dokBreite
set y2 to y1 + dokHoehe
set aktInddSeiten to 1
else
if filmBreite is greater than (x2 + abstand + dokBreite) then
if i is 1 then
if filmHoehe is greater than (y2 + abstand + dokHoehe) then
set x1 to x2 + abstand
set x2 to x1 + dokBreite
set y1 to y2 - dokHoehe
set y2 to y1 + dokHoehe
else
set x1 to 1
set y1 to 1
set x2 to x1 + dokBreite
set y2 to y1 + dokHoehe
set aktInddSeiten to aktInddSeiten + 1
end if
else
set x1 to x2 + abstand
set x2 to x1 + dokBreite
end if
else if filmHoehe is greater than (y2 + abstand + dokHoehe) then
set x1 to 1
set x2 to x1 + dokBreite
set y1 to y2 + abstand
set y2 to y1 + dokHoehe
else if (y2 + abstand + dokHoehe) is greater than filmHoehe then
set x1 to 1
set y1 to 1
set x2 to x1 + dokBreite
set y2 to y1 + dokHoehe
set aktInddSeiten to aktInddSeiten + 1
end if
end if
tell application "Adobe InDesign CC 2017"
tell active document
if altSeiten is less than aktInddSeiten then
tell document preferences to set properties to {pages per document:aktInddSeiten}
end if
set reEck to make rectangle at page aktInddSeiten with properties {geometric bounds:{y1, x1, y2, x2}}
set stroke color of reEck to item 1 of swatches
place alias (n as string) on reEck
end tell
end tell
end if
return {x1, y1, x2, y2, aktInddSeiten}
end check