InDesign Space Before

Using InDesign CS2:
I am trying to apply “space before” to just the paragraphs within a selected line(s) of text. The issue I am having is that I can’t figure out a way to target just those paragraphs within a selected group of text within a text frame.

For example: If I use the cursor and highlight the first 3 lines (of the 7 lines below) with my Text tool, I would want the script to apply the space before to just paragraph “example line 1”, “example line 2”, “example line 3”.

example line 1
example line 2
example line 3
example line 4
example line 5
example line 6
example line 7

My script is not working, but it is close. It targets all the paragraphs instead of just the selected paragraphs.

Any help would be greatly appreciated.

Thanks in advance.


tell application "Adobe InDesign CS2"
	set theSelection to (get selection)
	set theStory to parent story of item 1 of theSelection
	tell document 1
		set theSpace to get space before of object reference of paragraph 1 of theStory as number
		set space before of object reference of paragraphs of theStory to theSpace + "1"
	end tell
end tell

Hi, Jeff. You are directing the commands to the parent story, but the selection is really the target object. Try this:

tell application "InDesign CS"'s document 1 to set selection's paragraphs's space before to (selection's paragraph 1's space before) + 1

Marc, you are a lifesaver. I can’t believe you made this into a one-liner. I was left with one small issue. I did not want to apply a single value of space before to the selected paragraphs with the addition of plus one. There may be times that within the selection, different paragraphs have different space before values. Therefore I choose to repeat through each paragraph and add 1 pt to each. With you script and a simple repeat it works out perfectly.

Many thanks

tell application "Adobe InDesign CS2"'s document 1 to set xCount to count of paragraphs in selection
set x to 1
repeat until x is equal to xCount + 1
		tell application "Adobe InDesign CS2"'s document 1 to set selection's paragraph x's space before to (selection's paragraph x's space before) + 1
	end try
	set x to x + 1
end repeat