Indesign Text Extraction script?

Hello,

I’m fairly new to the world of scripting. I was wondering if there was a script that would extract all of the text from an Indesign CS document?

I know I can extract the text with multiple story editors and just paste that into a new document but was wondering if there might be a script that would extract all of the text (captions, body copy, formatting, styling, etc) without going into the indesign story editor or even actually opening the document.

Any help would be appreciated.

thanks

Where do you want the text to go? I don’t think it would be to difficult to get all the text from an InDesign CS document, but what are you going to do with that text? Also, I don’t think there’s any way to get the text without opening the document.

Yes you could do this by scripting - but how about an easier solution? Export the document as a PDF then use Acrobat 6 (I think reader works) to save it as an RTF file?
iolaire

The true scripting solution to this can be found at the Adobe Forums:
http://www.adobeforums.com/cgi-bin/webx?13@59.KpcLcYJdIO1.2@.3bb4a641/0
titled:
ExportAllStories - The addendum
Good luck, iolaire


--ExportAllStories.as
--An InDesign CS AppleScript
--
--Exports all stories in an InDesign document in a specified text format.
--InDesign exports each story as a separate file, and names each
--file using the story's ID.
--
--For more on InDesign scripting, go to http://www.adobe.com/products/indesign/scripting.html
--or drop by the InDesign Scripting User to User forum at http://www.adobeforums.com.
--
tell application "InDesign CS"
	if (count documents) > 0 then
		if (count stories of active document) > 0 then
			my myDisplayDialog()
		else
			display dialog "The active document contains no text. Please open a document containing text and try again."
		end if
	else
		display dialog "No documents are open. Please open a document and try again."
	end if
end tell
on myDisplayDialog()
	tell application "InDesign CS"
		set myDialog to make dialog with properties {name:"ExportAllStories"}
		tell myDialog
			--Add a dialog column.
			tell (make dialog column)
				tell (make border panel)
					make static text with properties {static label:"Export as:"}
					set myExportFormatButtons to make radiobutton groups
					tell myExportFormatButtons
						make radiobutton control with properties {static label:"Text Only", checked state:true}
						make radiobutton control with properties {static label:"RTF"}
						make radiobutton control with properties {static label:"InDesign Tagged Text"}
					end tell
				end tell
			end tell
		end tell
		set myReturn to show myDialog
		if myReturn is true then
			--Get the values from the dialog box.
			set myExportFormat to selected button of myExportFormatButtons
			destroy myDialog
			my myExportAllStories(myExportFormat)
		else
			destroy myDialog
		end if
	end tell
end myDisplayDialog

--myExportStories function takes care of exporting the stories.
--myExportFormat is a number from 0-2, where 0 = text only, 1 = rtf, and 3 = tagged text.
--myFolder is a reference to the folder in which you want to save your files.
on myExportAllStories(myExportFormat)
	set myFolder to choose folder with prompt "Select a folder in which to store the exported files"
	if myFolder is not equal to "" then
		tell application "InDesign CS"
			repeat with myCounter from 1 to (count stories of active document)
				set myStory to story myCounter of active document
				set myID to id of myStory
				if myExportFormat = 0 then
					set myFormat to text type
					set myExtension to ".txt"
				else if myExportFormat = 1 then
					set myFormat to RTF
					set myExtension to ".rtf"
				else if myExportFormat = 2 then
					set myFormat to tagged text
					set myExtension to ".txt"
				end if
				set myFileName to "StoryID" & myID & myExtension
				set myFilePath to (myFolder as string) & myFileName
				tell myStory
					export format myFormat to (myFilePath as string)
				end tell
			end repeat
		end tell
	end if
end myExportAllStories

That is one o the scripts in your Indesign Cs Techincal info Folder on the Cd.
If you want to use this script with Cs you need to place it in

Applications:Indesign CS:Presets:Scripts

I am learning all this mess because I want to take a few things from Cs to
filemaker pro 5
The cd has plenty of nifty scripts that you can use…

How would you modify that script so that all the files are compiled into a single text file? I’m kinda new at this and not always sure where to apply/input changes so keep that in mind when you reply. I know there is an “append” command but not sure how to apply.

Still looking for a solution that would copy all the text (or selected stories) into a single .txt, .rtf or word file. We manually have to copy tons of unlinked text boxes back into a Word file after we finish a series of brochures so we have a copy of the text in Word at the end of the year. Any ideas?

This is the closest we’ve gotten to solving this problem but it doesn’t quite work. David Bayne came up with this but with the following warning…ok… i have a script that works on making the stories go into one text frame…but… i would advise on using a test file first cause it doesnt just copy the text and exports it… it TAKES the text out of the spot and places it in a very very small text frame in the top left corner of the document…
here is the script though. I am working on how to get it to export it to an rtf with ALL the stories in one file not seperate files.

This may be workable if it didn’t make a tiny text box or even just copied it to the clipboard so I could then paste to Word after it’s done compiling the stories. Any other ideas?


tell application "InDesign CS"
	tell document 1
		set allStories to stories
		make text frame at beginning of page 1
		repeat with i from 1 to count of allStories
			move item i of allStories to after insertion point -1 of parent story of text frame 1
			set contents of insertion point -1 of parent story of text frame 1 to return & "***" & return
		end repeat
	end tell
end tell

I’d modify the original script so that each item from the original InDesign file was saved as a variable in Applescript. Since you don’t know how many items any particular InDesign document may have, you’d create a list variable using a looped control structure. Then, outside of InDesign, I’d use Applescript to gather those strings together and output as a single text file (or whatever else was required).

Use first ExportAllStories script and then this:

Kari