PDA

View Full Version : Another Script - you might find useful


RAT20V
06-10-2010, 11:34 AM
Hi all, i have played around with a old script today for batch exporting pdfs from a multiple document into single page documents with added random number and page number at the end.

But one thing that is bugging me is i cant seem to get rid of the .indd from the file name, i have tried a few variations of applescript delimiters but to no avail. i also would like it to add two zero's on front of a page number upto the value of 9 and to add one zero upto 99, this is for books and page layout that i would like to automate it so i can make my life easier.

You may find the script useful for batch processing pictures etc, at the moment it is set for indesign.

If you can help that would be amazing.

tell application "Adobe InDesign CS3"
activate
--set myPageNumPref to page numbering of general preferences


set myDocument to active document
set myFileName to name of myDocument
if (count documents) is equal to 0 then
display dialog "Please open a document" buttons " OK " default button 1 with icon caution
return -128
end if

set NumberOfPage to pages per document of document preferences of myDocument
set myFolder to (choose folder with prompt "Please select the folder you want to save your PDF pages in") as string

--Preset Dialog
set myLabelWidth to 100
set myDialog to make dialog with properties {name:"PDF Presets"}
tell myDialog
tell (make dialog column)
tell (make border panel)
tell (make dialog column)
tell (make dialog row)
tell (make dialog column)
make static text with properties {static label:"Choose Preset:", min width:myLabelWidth}
end tell
tell (make dialog column)
set myLabelsButtons to make radiobutton group
tell myLabelsButtons
set PresertList to name of every PDF export preset of application "Adobe InDesign CS3"
repeat with myButton in PresertList
make radiobutton control with properties {static label:myButton, checked state:false}
end repeat
end tell
end tell
end tell
end tell
end tell
end tell
end tell
set myResult to show myDialog
if myResult = true then

--don't know why but, set myPDFPreset to item (selected button of myLabelsButtons) of PresertList, returns the wrong button. The list starts at 0. So:
set x to selected button of myLabelsButtons
set myButtton to x + 1

set myPDFPreset to item myButtton of PresertList
end if
destroy myDialog


tell myDocument
with timeout of 5000 seconds
repeat with x from 1 to NumberOfPage
set mynumbertest to (name of page x of myDocument) as string
set mynumbercnt to count of items in mynumbertest
if mynumbercnt is less than 10 then
set myPageNumber to "00" & (name of page x of myDocument)
else

set myPageNumber to (name of page x of myDocument)

end if



tell application "Finder"
set duplicates to {}
-- get a random number of up to 5 digits
set an_item to random number from 0 to 99999
-- this line zero-pads the random number
set an_item to text -5 thru -1 of ("00000" & an_item) as text
if an_item is not in duplicates then
set end of duplicates to an_item
end if
end tell

set thePath to (myFolder & myFileName & "_" & myPageNumber & "_" & an_item & ".pdf")

--This is important for setting the page range, the tell has to be to ID
tell application "Adobe InDesign CS3"
set page range of PDF export preferences to (x as string)
export document 1 format PDF type to thePath using PDF export preset myPDFPreset
end tell
end repeat
end timeout
end tell
display dialog "FINISHED!"
end tell


best

Rat20v