InDesign CS2 Open, Select All, Ungroup, Text to Outlines, Export PDF

Hi,

I am very new to AppleScripting so please forgive the novelty of these questions. I have ordered an AppleScript book and an Automator book and am waiting for them to arrive.

I am trying to accomplish the following in this order:

Automatically open a series of highlighted/selected InDesign CS2 files (and perform the following to each of them):
Select all.
Ungroup as many times as needed to ungroup all groups.
Convert all text to outlines.
Export PDF to a specific location. (I would like to have a few different actions, each with a different pre-defined Adobe PDF Preset.)
Close each file.
I’d also like to automatically print these newly exported PDFs but that is my second priority right now.

So far, I have the following script that will export an InDesign CS2 file that is already opened using a specific Adobe PDF Preset. I’d like this script to be able to export a PDF with the filename that is the same as the InDesign file plus the .pdf suffix (instead of a specific filename listed in the script like I have). The script that I have been working with so far is from the Adobe website.

I’d also like the script to be built upon to accomplish the tasks listed above.

Any help would be appreciated. Again, I’m very new to this. Thanks for any help you can provide.

Josh

tell application “InDesign CS2”
set myPDFPresetName to “MyPDFPreset”
set found to false

-- Find existing PDF export presets of the same name
set numPresets to count PDF export presets
repeat with myCounter from 1 to numPresets
	set currentPresetName to name of PDF export preset myCounter
	if currentPresetName is equal to myPDFPresetName then
		-- Found, so don't make a new one
		set found to true
	end if
end repeat

-- Not found, so make a new PDF export preset
if found is false then
	make PDF export preset with properties {name:myPDFPresetName, view PDF:true, omit EPS:true}
end if

-- Try exporting
try
	set myErrorMessage to "No documents are open"
	set myDocument to active document
	set myErrorMessage to "Can't export PDF"
	-- Turn off user interaction to avoid dialogs
	set user interaction level to never interact
	tell myDocument
		-- Export the document as Adobe PDF
		export format "Adobe PDF" to "Macintosh HD:Test.pdf" using myPDFPresetName
	end tell
	-- Revert user interaction
	set user interaction level to interact with all
on error
	activate
	display dialog myErrorMessage
end try

end tell

Have a look at this post for how to export PDF and EPS from CS2
http://bbs.applescript.net/viewtopic.php?id=17969
Use script editor to access the dictionary for CS2 for syntax help.
Should get you started.
Chuckles :smiley:

Quickly thrown together, compiled but not tested but should get you a little closer:

on BuildList(DroppedItems)
	set NewList to {}
	repeat with AnItem in DroppedItems as list
		set AnItem to AnItem as string
		if the last character of AnItem is ":" then
			tell application "Finder"
				set FileList to (files of entire contents of alias AnItem whose name extension is "indd" as list)
			end tell
			repeat with AFile in FileList
				set AFile to AFile as string
				set end of NewList to AFile
			end repeat
		else
			tell application "Finder"
				if name extension of alias AnItem is "indd" then set end of NewList to AnItem
			end tell
		end if
	end repeat
	return NewList
end BuildList

on open (FileList)
	set FileList to BuildList(FileList)
	repeat with AFile in FileList
		set ThePath to (choose folder with prompt "Please select a folder to save the PDF to.") as string
		tell application "InDesign CS"
			set myPDFPresetName to "MyPDFPreset"
			set found to false
			-- Find existing PDF export presets of the same name
			set PDFpresets to name of every PDF export preset
			if PDFpresets does not contain myPDFPresetName then make PDF export preset with properties {name:myPDFPresetName, view PDF:true, omit EPS:true}
			
			-- Try exporting
			try
				set myDocument to open AFile
				set fileName to name of myDocument
				set myErrorMessage to "Can't export PDF"
				-- Turn off user interaction to avoid dialogs
				set user interaction level to never interact
				tell myDocument
					-- Export the document as Adobe PDF
					export format "Adobe PDF" to (ThePath & fileName) using myPDFPresetName
				end tell
				-- Revert user interaction
				set user interaction level to interact with all
			on error
				activate
				display dialog myErrorMessage
			end try
		end tell
	end repeat
end open

This is a drag and drop, so it needs to be saved as an application. Drop your files on it and it should (with possible tweeks needed) make PDF’s of all the files with an indd file extension in the files and folders dropped on the script.

Thanks so much for your input Chuckles66 and Jerome!

Chuckles66, your scripts for exporting PDF and EPS have been a big help in helping me get closer to my final desired script.

Jerome, your script worked flawlessly for me. Thanks! The current script that you gave me asks me where each file should be exported to. I’m working on altering it so that it only asks for that final destination once and exports all files to that location. Once I get that resolved, I’ll build into the script (before exporting) a select all, ungroup all groups (ungroups repeated in succession?), convert all text to outlines, then the export. Eventually, I’d also like to tie all of this into an Automator workflow and save it as a plug-in for the Finder.

Any insight that you might have into these things would be very appreciated. I’m doing the best I can putting together the resources that I have found but am still waiting to receive some training books that will speed up my progress.

Thanks again guys!

Josh

Yea, I woud definatly move the display dialog command for the save file path, also add in a close commend for each document. Like I said I threw those lines together quickly without testing them so I’m glad that they have helped you. The best references I have found for scripting Adobe products are their PDF guides for scripting, the application dictionary, their website and this one. Two other good websites for are:

http://olivier.berquin.free.fr/indesign/index.html
http://www.scriptingmatters.com/indesigncs_changes.php

Great stuff, Jerome! Thanks for helping me on my way. I’ll look into those two websites now.