QuarkXPress script for highlighting first word in headline

I’m trying to write a script which can auto-format paragraphs with decorative first digit.
Theoretically is’s quite easy, look my script down, but… very annoying thing is that i have to select every time all paragraph text.
Main question - can Quark recognize current paragraph from insertion point without selecting? Нow to get reference to whole current paragraph having only blinking cursor in it?

It’s another situation than referencing like text_story->paragraphs->words->characters.


set WordStyle to "Number"

tell application "QuarkXPress Passport 7"
	tell front document
		try
			set SelectedText to (a reference to every text of selection)
			get 1st word of SelectedText
			set properties of word 1 of every paragraph of SelectedText to {character style:character spec WordStyle}
			
		end try
		
	end tell
end tell

I think you give me the perfect advice!

Ок everybody i found the solution. So we have to think in terms of characters offset instead of text objects.
Here is full and working script.
It emphasizes a first word (in my case a digit) and adds tab after it. It also change a paragraph style for the text.


tell application "QuarkXPress Passport"
	activate
	try
		tell front document
			
			set ParaStyle to "Catalog Heading" --Paragraph style name
			set WordStyle to "Heading Number" --Character style name
			
			set ActiveStory to object reference of text of story 1 of current box
			set InsPoint to object reference of selection --Get Selection
			set InsPointOffset to offset of InsPoint --Get Selection Offset
			set myText to object reference of characters 1 thru InsPointOffset of ActiveStory --Get text range thru current position
			
			set ParaIndex to index of last paragraph of myText
			set StoryPara to object reference of paragraph ParaIndex of ActiveStory
			set StoryParaText to text of StoryPara
			
			using terms from application "Finder"
				set FirstSpace to offset of " " in StoryParaText
			end using terms from
			
			set style sheet of StoryPara to null
			set style sheet of StoryPara to style spec ParaStyle --Set paragraph style
			set character style of word 1 of StoryPara to character spec WordStyle --Set character style
			
			set character FirstSpace of StoryPara to "	"
			
		end tell
	end try
end tell