Quark object reference query, help required please...

Hi there,

Over the weekend I was doing some scripting and came up with a small query regarding an object reference query.

Here’s a brief overview. I have a text box with some tabbed text in it, shown below:-

New 1 Item 1
2 Item 2
3 Item 3
New 4 Item 4
New 5 Item 5
6 Item 6
etc…

What I trying to do is find each instance of the word ‘New’, select it and paste the contents of the clipboard, therefore replacing the word ‘New’.
In the sample i’m using there are only 3 instances of the word ‘New’.
When I run the script the first instance gets overlooked, as if no reference to it is made.
The second instance gets replaced as it should.
And, the third instance has the ‘ew’ of ‘New’ and the tab, after the word word ‘New’, replaced.

Here’s the code I’ve been using:-

set objRefNew to object reference of every word of story 1 of text box 1 where it is "New"
      repeat with thisInstance in objRefNew
           select thisInstance
           paste
      end repeat

Please can someone tell me why this might be happening?
I’ve had a read through a number of articles but as yet haven’t found the answer.
Is the object reference the problem?

Thanks in advance,

Nick

I have seen this before. I usually use this format for replacing text as it seems to work better.

tell application "QuarkXPress"
	activate
	tell front document
		set NewText to the clipboard
		tell story 1 of text box 1
			set every text where it is "New" to NewText
		end tell
	end tell
end tell

Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Hi MattBoy,

Thanks for the reply and for the code.
I should have explained the query a little better. The content I’m trying to paste is a picture box that I’ve just created and cut to the clipboard. I think this makes it a completely new ball game. If I try your code I get a ‘Can’t make data into expected type’ error, I think that’s because I’m trying to paste a picture box and not text.
Is there a way to amend your script to take this into account?

Thanks once again for the help though, I think the code will come in handy for doing text amends.

Regards,

Nick

Ah, that does make a difference.

Going back to your original question, I believe what happens in your original script is you get all of your object references to the words and then when you paste, you change the number of letters in the word so the reference to where the next word starts is off. I tested the original script with a picture box on the clipboard and when it replaced the first “NEW” with a box, the next “New” was off by 2 characters where it dropped in the box.

Anyway, I tried this and it seems to work. Basically, it counts how many times the word appears and then goes through then repeats, getting all references and replacing the first one before starting over and getting all references again.

tell application "QuarkXPress"
	activate
	tell front document
		set objRefCount to count of (every word of story 1 of text box 1 where it is "New")
		repeat with x from 1 to objRefCount
			set objRefNew to (object reference of every word of story 1 of text box 1 where it is "New")
			select (item 1 in objRefNew)
			paste
		end repeat
	end tell
end tell

Model: G5
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Thanks for the reply Matt-boy and for the code.

I’ll have a play with that later. It’s quite a good way round it though could add quite a bit of time if there are quite a few to replace.

I have found that adding an extra line, as shown below, at the start seems to solve the problem, not quite sure why?

     0   Item 0<<<<

New 1 Item 1
2 Item 2
3 Item 3
New 4 Item 4
New 5 Item 5
6 Item 6
etc…

Thanks again for your help :slight_smile:

Regards,

Nick