Script behaves differently when run in AS Editor and InDesign CS4

Hi

Sorry if this post is a repeat question. I’m not sure exactly how to keyword search for this issue, so I may have missed an already-provided answer.

I’m writing the following script to capture some paragraph and character style properties from an InDesign CS4 document and export them to a cascading style sheet file that I can use in EPUB documents. When I run the script though Applescript, it works fine, but when I run it through InDesign’s scripts panel, some values–those with default or undefined values–are recorded in a different format. For example, when run through Applescript Editor, the capitalization property is written as “case: normal.” When run through the InDesign scripts panel, though, the same code generates “case: «constant ****norm».” Obviously, I could write additional code to find and replace the unwanted value, but I don’t understand why it’s even happening, and it would be a faster script if I could get it to output correctly from the start. Any thoughts on why the discrepancy occurs would be greatly appreciated.

I’m very new to Applescript (this is my first script), and I don’t fully understand the object model yet, which is where I suspect the problem is coming from; forgive me if this seems like a very elementary and clunky script.

Thanks.


tell application "Adobe InDesign CS4"
	--turn off typographers' quotes
	set typographers quotes of text preferences to false
	--set refernces to active document and collection document
	set myDocument to active document
	set myStylesDocument to make document
	--create text frame in collection document
	tell myStylesDocument
		make new text frame with properties {geometric bounds:{3, 3, 63, 48}}
		set text column count of text frame preferences of text frame 1 of myStylesDocument to 3
	end tell
	--itemize css relevant properties from each paragraph style
	repeat with myParagraphStyle in every paragraph style of myDocument
		if name of myParagraphStyle is not "[No Paragraph Style]" and name of myParagraphStyle is not "[Basic Paragraph]" and name of myParagraphStyle is not "PAGER" then
			tell myStylesDocument
				set contents of insertion point -1 of story 1 to ("p." & name of myParagraphStyle as string) & " {" & return ¬
					& tab & "font-family: " & "\"" & (applied font of myParagraphStyle as string) & "\";" & return ¬
					& tab & "font-size: " & (point size of myParagraphStyle as string) & ";" & return ¬
					& tab & "line-height: " & (leading of myParagraphStyle as string) & ";" & return ¬
					& tab & "letter-spacing: " & (kerning method of myParagraphStyle as string) & ";" & return ¬
					& tab & "word-spacing: " & (tracking of myParagraphStyle as string) & ";" & return ¬
					& tab & "vertical-align: " & (baseline shift of myParagraphStyle as string) & ";" & return ¬
					& tab & "margin-left: " & (left indent of myParagraphStyle as string) & ";" & return ¬
					& tab & "margin-right: " & (right indent of myParagraphStyle as string) & ";" & return ¬
					& tab & "text-indent: " & (first line indent of myParagraphStyle as string) & ";" & return ¬
					& tab & "margin-top: " & (space before of myParagraphStyle as string) & ";" & return ¬
					& tab & "margin-bottom: " & (space after of myParagraphStyle as string) & ";" & return ¬
					& tab & "orphans: " & (keep first lines of myParagraphStyle as string) & ";" & return ¬
					& tab & "widows: " & (keep last lines of myParagraphStyle as string) & ";" & return ¬
					& tab & "color: " & (name of fill color of myParagraphStyle as string) & ";" & return ¬
					& tab & "tint: " & (fill tint of myParagraphStyle as string) & ";" & return ¬
					& tab & "case: " & (capitalization of myParagraphStyle) & ";" & return ¬
					& tab & "position: " & (position of myParagraphStyle as string) & ";" & return ¬
					& tab & "underline: " & (underline of myParagraphStyle as string) & ";" & return ¬
					& tab & "strikethrough: " & (strike thru of myParagraphStyle as string) & ";" & return ¬
					& tab & "justification: " & (justification of myParagraphStyle as string) & ";" & return ¬
					& "}" & return
			end tell
		end if
	end repeat
	--itemize css relevant properties from each character style
	repeat with myCharacterStyle in every character style of myDocument
		if name of myCharacterStyle is not "[None]" and name of myCharacterStyle is not "[Basic Paragraph]" and name of myCharacterStyle is not "pager" then
			tell myStylesDocument
				set insertion point -1 of story 1 to ("span." & name of myCharacterStyle as string) & " {" & return ¬
					& tab & "font-family: " & "\"" & (applied font of myCharacterStyle as string) & "\";" & return ¬
					& tab & "font-size: " & (point size of myCharacterStyle as string) & ";" & return ¬
					& tab & "line-height: " & (leading of myCharacterStyle as string) & ";" & return ¬
					& tab & "letter-spacing: " & (kerning method of myCharacterStyle as string) & ";" & return ¬
					& tab & "word-spacing: " & (tracking of myCharacterStyle as string) & ";" & return ¬
					& tab & "vertical-align: " & (baseline shift of myCharacterStyle as string) & ";" & return ¬
					& tab & "color: " & (fill color of myCharacterStyle as string) & ";" & return ¬
					& tab & "tint: " & (fill tint of myCharacterStyle as string) & ";" & return ¬
					& tab & "case: " & (capitalization of myCharacterStyle as string) & ";" & return ¬
					& tab & "position: " & (position of myCharacterStyle as string) & ";" & return ¬
					& tab & "underline: " & (underline of myCharacterStyle as string) & ";" & return ¬
					& tab & "strikethrough: " & (strike thru of myCharacterStyle as string) & ";" & return ¬
					& "}" & return
			end tell
		end if
	end repeat
	set myPath to (path to desktop)
	export first story of myStylesDocument to file (myPath & "template.css" as string) format text type
	close myStylesDocument saving no
	--turn on typographers' quotes
	set typographers quotes of text preferences to true
	display dialog ("Finished. Now process template.css file through EPUB_Processor macro in Microsoft Word.")
end tell

When you run from a script editor, it loads InDesign’s scripting dictionary and looks up the text equivalents of the scripting codes for you. When you run the script from InDesign, the scripting dictionary isn’t loaded (because it’s otherwise not needed).

The simple rule is: don’t coerce keywords to strings.

Thanks, Shane. I’m not 100% sure what your reply means, but I think I can figure it out. If I continue to have trouble, I’ll repost.

m.