Okay, So,
I have an Indesign script, you drop pdf files directly onto it,
it sorts pages (say 0001_#.pdf, 0002_#.pdf, i_#.pdf, ii_#.pdf)
then opens indesign and places them in a new document according to user input and dimensions of the pdf files.
Problem is, the roman numeral labeled pages come first in the new document even though they are alphabetically last.
How can this be corrected?
property kNumPages : 999
property kSaveLastDoc : false
property widthDefault : 8
property heightDefault : 10
property percentDefault : 100
property defaultBigger : 1
global gDocNew, gDocName, gCurPage, gCurSpread, gCurBox, gNumBoxes, gDocWidth, gDocHeight, gMargin, grfkheight, grfkwidth, BindOffset, gScale, myDialog, pagesFacing, gBleedSize, theBleed
global gFirstOne, gLastOne, gIsMultiDoc, gDocJustMade, gFileType, gWdOrigin, gHtOrigin, gMakeSmaller
global keepWidth, SecWidth, SecHtOrig, gPleaseRotate, theRectangle, OrigRulOrig, gMasterOffset, positionGuide, positionLeft, ImagesPerPage, gVertOffset
on open droppedItems
display dialog "For best results, all files should have the same dimensions and that the type file comes alphabetically directly following the image file. Also, all files must be in the same folder, remember to drop all files on script - not folder."
doInitStuff()
set gRecordNumber to count droppedItems
set droppedItems to my quickSort(droppedItems, 1, gRecordNumber)
repeat with tItem in droppedItems
set itsInfo to (info for file tItem)
if folder of itsInfo then -- folders dropped
searchFolder(tItem as string)
else -- files dropped
if gCurBox > ImagesPerPage then
doNewPage()
end if
doImageStuff(tItem as string)
end if
end repeat
tell application "Adobe InDesign CC 2019"
tell page gCurPage of document gDocName
if (gCurPage mod 2) = 0 then
tell theRectangle
set currentBounds to {-gBleedSize, -gBleedSize, (gDocHeight + gBleedSize), (gDocWidth + gBleedSize)}
set geometric bounds to currentBounds
end tell
end if
end tell
end tell
if kSaveLastDoc and gIsMultiDoc then
doSaveDoc()
end if
tell application "Adobe InDesign CC 2019"
tell view preferences of document gDocName
set horizontal measurement units to inches
set vertical measurement units to inches
end tell
if pagesFacing is true then
tell document preferences of document gDocName
set facing pages to true
end tell
end if
end tell
with timeout of 600000 seconds
activate
display dialog "Completed!" buttons {"Okay"} default button 1 with icon 2
end timeout
tell application "Adobe InDesign CC 2019"
set gDocName to activate
end tell
end open
on doInitStuff()
set gIsMultiDoc to false
set gDocJustMade to true
set pagesFacing to false
set positionGuide to ""
set positionLeft to ""
set gDocWidth to 720
set gDocHeight to 720
set gCurBox to 1
tell application "Adobe InDesign CC 2019"
my myDialog()
my doNewDoc()
end tell
tell application "Finder"
set positionGuide to activate
set positionGuide to the button returned of (display dialog "Which aspect of the page should remain as it was before?" buttons {"Gutter", "Thumb Edge", "Center"} default button 1)
--if the button returned of (display dialog "Which aspect of the page should remain as it was before?" buttons {"Gutter", "Thumb Edge", "Center"}) is "Gutter" then
if positionGuide = "Gutter" then
set positionLeft to 1
else
if positionGuide = "Thumb Edge" then
--if the button returned of (display dialog "Which aspect of the page should remain as it was before?" buttons {"Gutter", "Thumb Edge", "Center"}) is "Thumb Edge" then
set positionLeft to 0
else
set positionGuide to "Center"
end if
end if
end tell
end doInitStuff
on myDialog()
tell application "Adobe InDesign CC 2019"
set theDialog to make dialog with properties {can cancel:true}
activate
tell theDialog
set myDialogColumn to make dialog column
tell myDialogColumn
set myBorderPanel0 to make border panel
tell myBorderPanel0
make static text with properties {static label:"Items per page:"}
set myItemNum to make dialog column
tell myItemNum
set itemNum to make real editbox with properties {edit value:1, small nudge:1, minimum value:1, maximum value:15, min width:60}
end tell
end tell
set myBorderPanel1 to make border panel
tell myBorderPanel1
make static text with properties {static label:"New Width:"}
set myCW to make dialog column
tell myCW
set theWidth to make measurement editbox with properties {edit value:576, edit units:inches, small nudge:0.5, minimum value:1, maximum value:2000, min width:60}
end tell
end tell
set myBorderPanel2 to make border panel
tell myBorderPanel2
make static text with properties {static label:"New Height:"}
set myCH to make dialog column
tell myCH
set theHeight to make measurement editbox with properties {edit value:720, edit units:inches, small nudge:0.5, minimum value:1, maximum value:2000, min width:60}
end tell
end tell
set myBorderPanel3 to make border panel
tell myBorderPanel3
make static text with properties {static label:"Bleed"}
set myB to make dialog column
tell myB
set theBleed to make measurement editbox with properties {edit value:9, edit units:inches, small nudge:0.5, minimum value:0, maximum value:72, min width:60}
end tell
end tell
set myBorderPanel4 to make border panel
tell myBorderPanel4
make static text with properties {static label:"Percentage:"}
set myPC to make dialog column
tell myPC
set thePercentage to make real editbox with properties {edit value:100, small nudge:1, minimum value:10, maximum value:500, min width:60}
end tell
end tell
set myBorderPanel4a to make border panel
tell myBorderPanel4a
make static text with properties {static label:"Vertical Offset"}
set myOffS to make dialog column
tell myOffS
set theOffset to make measurement editbox with properties {edit value:0, edit units:inches, small nudge:0.5, minimum value:-144, maximum value:144, min width:60}
end tell
end tell
set myBorderPanel5 to make border panel
tell myBorderPanel5
make static text with properties {static label:"Images being placed are how much bigger than original trim size?"}
set myM to make dialog column
tell myM
set theDifference to make measurement editbox with properties {edit value:72, edit units:inches, small nudge:0.5, minimum value:0, maximum value:288, min width:60}
end tell
end tell
set myBorderPanel6 to make border panel
tell myBorderPanel6
make static text with properties {static label:"Facing Pages:"}
set myFP to make dialog column
tell myFP
set doPagesFace to make checkbox control with properties {min width:45}
tell myBorderPanel6
set checked state of doPagesFace to true
end tell
end tell
end tell
end tell
end tell
set myResult to show theDialog
if myResult = true then
set ImagesPerPage to (edit value of itemNum) as real
set gDocWidth to (edit value of theWidth) as real
set gDocHeight to (edit value of theHeight) as real
set gBleedSize to (edit value of theBleed) as real
set newPercentage to (edit value of thePercentage) as real
set gVertOffset to (edit value of theOffset) as real
set amtBigger to (edit value of theDifference) as real
set pagesFacing to (checked state of doPagesFace)
end if
set gScale to newPercentage
set gMasterOffset to ((amtBigger / 2) * (gScale / 100))
destroy theDialog
end tell
end myDialog
on quickSort(a, L, R)
set ctr to L
set n to R
set aRef to item L of a as string
repeat while ctr < n
repeat while (aRef < item n of a) and (ctr < n)
set n to n - 1
end repeat
if n is not ctr then
set item ctr of a to item n of a
set ctr to ctr + 1
end if
repeat while (aRef > item ctr of a) and (ctr < n)
set ctr to ctr + 1
end repeat
if n is not ctr then
set item n of a to item ctr of a
set n to n - 1
end if
end repeat
set item n of a to aRef
if L < n then
quickSort(a, L, n - 1)
end if
if R > ctr then
quickSort(a, ctr + 1, R)
end if
return a
end quickSort
on doNewDoc()
tell application "Adobe InDesign CC 2019"
set gCurPage to 1
set gCurBox to 1
set gDocJustMade to true
tell view preferences
set horizontal measurement units to points
set vertical measurement units to points
end tell
set gDocNew to make new document with properties {document preferences:{facing pages:"true", document bleed bottom offset:gBleedSize, document bleed inside or left offset:gBleedSize, document bleed top offset:gBleedSize, document bleed outside or right offset:gBleedSize, document bleed uniform size:true}}
set gDocName to name of gDocNew
tell document preferences of gDocNew
set facing pages to false
set page width to (gDocWidth & " pt" as string)
set page height to (gDocHeight & " pt" as string)
end tell
activate
tell document gDocName
tell view preferences
set horizontal measurement units to points
set vertical measurement units to points
end tell
repeat with i from 1 to ImagesPerPage
set theLayer to "Layer " & i
if exists layer theLayer then
--set theLayer to theLayer
else
make layer with properties {name:theLayer, visible:true, locked:false}
end if
end repeat
end tell
end tell
end doNewDoc
on doImageStuff(tFile)
set theImage to (tFile)
set imageName to (tFile) as alias
set fileInfo to info for imageName
tell application "Adobe InDesign CC 2019"
set oldCrops to PDF crop of PDF place preferences
set PDF crop of PDF place preferences to crop media
tell page gCurPage of document gDocName
set theBounds to {"0 pt", "0 pt", "144 pt", "144 pt"}
set theLayer to ("Layer " & gCurBox)
set theRectangle to make rectangle with properties ¬
{geometric bounds:theBounds, name:"pic" & gCurBox, fill color:"None", stroke color:"None", item layer:theLayer}
with timeout of 600000 seconds
place imageName on theRectangle with properties {horizontal scale:gScale, vertical scale:gScale}
end timeout
tell theRectangle to fit given frame to content
set grfkbnds to geometric bounds of theRectangle
set grfkwidth to ((item 4 of grfkbnds) - (item 2 of grfkbnds)) as real
set grfkheight to ((item 3 of grfkbnds) - (item 1 of grfkbnds)) as real
end tell
tell page gCurPage of document gDocName
tell theRectangle
if positionGuide = "Center" then
set geometric bounds to {(((gDocHeight - grfkheight) / 2) + gVertOffset), ((gDocWidth - grfkwidth) / 2), ((((gDocHeight - grfkheight) / 2) + gVertOffset) + grfkheight), (((gDocWidth - grfkwidth) / 2) + grfkwidth)}
tell theRectangle to fit given content to frame
else
if (gCurPage mod 2) = positionLeft then
set geometric bounds to {(((gDocHeight - grfkheight) / 2) + gVertOffset), -gMasterOffset, ((((gDocHeight - grfkheight) / 2) + grfkheight) + gVertOffset), (-gMasterOffset + grfkwidth)}
tell theRectangle to fit given content to frame
else
set geometric bounds to {(((gDocHeight - grfkheight) / 2) + gVertOffset), (gMasterOffset + gDocWidth - grfkwidth), ((((gDocHeight - grfkheight) / 2) + grfkheight) + gVertOffset), (gMasterOffset + gDocWidth)}
tell theRectangle to fit given content to frame
end if
end if
if pagesFacing is true then
if gCurPage > 1 then
if (gCurPage mod 2) = 0 then
set currentBounds to {-gBleedSize, -gBleedSize, (gDocHeight + gBleedSize), gDocWidth}
set geometric bounds to currentBounds
else
set currentBounds to {-gBleedSize, 0, (gDocHeight + gBleedSize), (gDocWidth + gBleedSize)}
set geometric bounds to currentBounds
end if
else
set currentBounds to {-gBleedSize, -gBleedSize, (gDocHeight + gBleedSize), (gDocWidth + gBleedSize)}
set geometric bounds to currentBounds
end if
else
set currentBounds to {-gBleedSize, -gBleedSize, (gDocHeight + gBleedSize), (gDocWidth + gBleedSize)}
set geometric bounds to currentBounds
end if
end tell
end tell
set PDF crop of PDF place preferences to oldCrops
end tell
set gCurBox to gCurBox + 1
set gLastOne to name of fileInfo
end doImageStuff
on doNewPage()
set gCurBox to 1
if (gCurPage ≥ kNumPages) then
set gIsMultiDoc to true
doSaveDoc()
doNewDoc()
else
set gCurPage to gCurPage + 1
tell application "Adobe InDesign CC 2019"
tell document 1
make page at end
end tell
end tell
end if
end doNewPage
on doSaveDoc()
tell application "Finder"
if not (folder kSavePath exists) then
set kSavePath to (choose folder with prompt "Choose location to save new indd file")
end if
end tell
tell application "Adobe InDesign CC 2019"
save document gDocName in (kSavePath & gFirstOne & "-" & gLastOne) without template
close document 1 saving no
end tell
end doSaveDoc