Hi
I have an Applescript that will pdf an indesign file but I want to improve it.
I want it to be a droplet that can process multiple files.
Here is the script and thanks in advance to anyone who can help.
tell application "Adobe InDesign CS5.5"
set user interaction level of script preferences to never interact
activate
set My_Pdf_Presets to name of every PDF export preset
set MyPdfPreset to choose from list My_Pdf_Presets with prompt "Choose a preset"
if MyPdfPreset is false then
display dialog "User Cancelled!" buttons "OK" giving up after 60
error number -128
end if
set properties of PDF export preferences to properties of PDF export preset (item 1 of MyPdfPreset)
set page range of PDF export preferences to all pages
set MyFolder to file path of active document
tell application "Finder"
if (exists folder "PDFs" of folder MyFolder) is false then
make new folder at MyFolder with properties {name:"PDFs"}
end if
end tell
set MyDocName to name of active document
set OrigDelims to text item delimiters of AppleScript
set text item delimiters of AppleScript to {"."}
set MyShortName to text item 1 of MyDocName
set text item delimiters of AppleScript to OrigDelims
set MyFilePath to MyFolder & "PDFs" & ":" & MyShortName & ".pdf" as string
tell active document
export format PDF type to MyFilePath without showing options
close saving no
end tell
set user interaction level of script preferences to interact with all
activate
display dialog "Your PDFs are ready" with icon 1 buttons {"OK"} default button "OK"
end tell
hi,
there are droplate templates at http://www.macosxautomation.com/applescript/pkg/droplet-templates.zip.
Hi Hans,
I have plugged it in but it isn't working.
I know very little about Applescript can you tell me what I am doing wrong?
Thanks,
property type_list : {} -- eg: {"PICT", "JPEG", "TIFF", "GIFf"}
property extension_list : {"indd", "idml", "inx"}
property typeIDs_list : {} -- eg: {"public.jpeg", "public.tiff", "public.png"}
-- This droplet processes files dropped onto the applet
on open these_items
repeat with i from 1 to the count of these_items
set this_item to item i of these_items
set the item_info to info for this_item
try
set this_extension to the name extension of this_info
on error
set this_extension to ""
end try
try
set this_filetype to the file type of this_info
on error
set this_filetype to ""
end try
try
set this_typeID to the type identifier of this_info
on error
set this_typeID to ""
end try
if (folder of the item_info is false) and (alias of the item_info is false) and ((this_filetype is in the type_list) or (this_extension is in the extension_list) or (this_typeID is in typeIDs_list)) then
process_item(this_item)
end if
end repeat
end open
-- this sub-routine processes files
on process_item(this_item)
tell application "Adobe InDesign CS5.5"
set user interaction level of script preferences to never interact
activate
set My_Pdf_Presets to name of every PDF export preset
set MyPdfPreset to choose from list My_Pdf_Presets with prompt "Choose a preset"
if MyPdfPreset is false then
display dialog "User Cancelled!" buttons "OK" giving up after 60
error number -128
end if
set properties of PDF export preferences to properties of PDF export preset (item 1 of MyPdfPreset)
set page range of PDF export preferences to all pages
set MyFolder to file path of active document
tell application "Finder"
if (exists folder "PDFs" of folder MyFolder) is false then
make new folder at MyFolder with properties {name:"PDFs"}
end if
end tell
set MyDocName to name of active document
set OrigDelims to text item delimiters of AppleScript
set text item delimiters of AppleScript to {"."}
set MyShortName to text item 1 of MyDocName
set text item delimiters of AppleScript to OrigDelims
set MyFilePath to MyFolder & "PDFs" & ":" & MyShortName & ".pdf" as string
tell active document
export format PDF type to MyFilePath without showing options
close saving no
end tell
set user interaction level of script preferences to interact with all
activate
display dialog "Your PDFs are ready" with icon 1 buttons {"OK"} default button "OK"
end tell
end process_item
Third day raining nonstopp ;-)
So, try this:
(*Has to be saved as programm …
Works with folders and files dropped onto
Tested with ID CS 5.5; OSX 10.7.4
*)
property pdfPreset : ""
property counter : 0
property errorsOccurred : 0
on open these_items
set counter to 0
set errorsOccurred to 0
--get pdf export preset
set pdfPreset to getExportPreset()
if pdfPreset is false then
activate
display alert "No PDF-Preset selected."
else
--loop
repeat with i from 1 to the count of these_items
set this_item to (item i of these_items)
--'info for' should be replaced in future but for now it's easy to use ...
set the item_info to info for this_item
if folder of the item_info is true then
process_folder(this_item)
else
set {fileContainer, shortName} to my getContainer(this_item)
process_item(this_item as text, fileContainer, shortName, pdfPreset)
end if
end repeat
activate
display dialog "Finished. | " & counter & " files have been exported. | " & errorsOccurred & " Errors occurred."
end if
end open
on process_folder(this_folder)
set these_items to list folder this_folder without invisibles
repeat with i from 1 to the count of these_items
set this_item to alias ((this_folder as text) & (item i of these_items))
set the item_info to info for this_item
if folder of the item_info is true then
process_folder(this_item)
else
set {fileContainer, shortName} to my getContainer(this_item)
process_item(this_item as text, fileContainer, shortName, pdfPreset)
end if
end repeat
end process_folder
--get folder and short filename (without possible extension)
on getContainer(this_item)
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set folderPath to ((text items 1 thru -2 of (this_item as string)) as text) & ":"
set trimmedName to text item -1 of (this_item as string)
if trimmedName contains "." then
set AppleScript's text item delimiters to {"."}
set trimmedName to text 1 thru text item -2 of trimmedName
end if
set AppleScript's text item delimiters to TID
return {folderPath, trimmedName}
end getContainer
on getExportPreset()
tell application "Adobe InDesign CS5.5"
set My_Pdf_Presets to name of every PDF export preset
set MyPdfPreset to (choose from list My_Pdf_Presets with prompt "Choose a preset to process the dropped files" without multiple selections allowed)
if MyPdfPreset is false then
return false
else
return item 1 of MyPdfPreset
end if
end tell
end getExportPreset
on process_item(this_item, fileContainer, shortName, pdfPreset)
do shell script "mkdir -p " & quoted form of POSIX path of (fileContainer & "PDFs")
try
tell application "Adobe InDesign CS5.5"
set myDoc to open alias this_item
set pdfFilePath to fileContainer & "PDFs" & ":" & shortName & ".pdf" as string
set page range of PDF export preferences to all pages
set chosedPdfPreset to PDF export preset pdfPreset
export myDoc format PDF type to pdfFilePath using chosedPdfPreset without showing options
close myDoc saving no
set counter to counter + 1
end tell
on error e
set errorsOccurred to errorsOccurred + 1
display dialog "My problem: " & e giving up after 3
end try
end process_item
North America
Europe, Middle East and Africa
Asia Pacific