Script problem

Whats wrong with this script can’t get it to work. I have a quark document open and all I am trying to do is ad a new text box to it. With the box
origin Across 4 pt
origin down -135.125 pt
width 115.112 pt
Height 21.852

tell application “QuarkXPress™”
activate

try
	-- This line will ensure that a document is open, before proceeding
	if not (exists document 1) then error "No document is open."
	
	tell document 1
		
		--Create a new text box 
		NewBox to make new text box at beginning with properties ¬
			{bounds:{"0"", "0"", "" & thisBox & """, "2.167""}, color:¬
				"none", frame:{color:"black", style:solid, width:"0 pt"}}
		display dialog "Complete"
	end tell
	
	
	
end try

end tell

First, things will be so much easier if you just use points, especially since you know the size in points.

tell app "QuarkXPress"
   tell document 1
       set properties to {horizontal measure:points, vertical measure:points}
   end
end

I find that I’m usually creating boxes dynamically, so I use variables to set the bounds. That way, I can easily manipulate the bounds and modularize text box creation with a handler.

set textTop to  -135.125
set textLeft to 4
set textBottom to (textTop + 21.852)
set textRight to (textLeft + 115.112) 
tell application "QuarkXPress?"
	tell document 1
		make new text box at beginning with properties ¬
		{bounds:{textTop, textLeft, textBottom, textRight}, color:null}
	end tell
end tell

One thing you cannot do is to set a variable to “make new box”. You can set your properties to a variable, though.

set boxProps to {bounds:{10,10, 110, 110}, color:null}
-- you'll notice in the above why I like to use points: no quote marks needed!
tell application "QuarkXPress?"
	tell document 1
		make new text box at beginning with properties boxProps
	end tell
end tell

This way you can just create a bunch of different box styles, if you want different boxes in your document.

Thanks this code does what I need it to do. I have added some code to it . How do I set the new text box so that the type is always 7pts. It will not paste into my newbox from my clipboard . I have info saved on to my clipboard that I want to paste into this box. If I do it manually and go to edit paste then it works.

Code:
set boxProps to {bounds:{10,10, 110, 110}, color:null}
set newbox to “”
– you’ll notice in the above why I like to use points: no quote marks needed!
tell application “QuarkXPress?”
tell document 1
set newbox to make new text box at beginning with properties boxProps
select newbox
set tool mode to content mode
paste
end tell
end tell

There are three ways that I can think of off-hand to set your text to 7 pts. First, a little QuarkXPress background. The reason that your text is coming in at 12 pts., auto leading is that that is the default for normal text in Quark. I guess they had to set it to something. To set your text to 7 pts. you can:

  1. Set your normal template to 7 pts. by editing your style sheet with no page open. Edit–>Style Sheets, select Normal and set the size and leading to your specs. This will mean that all pages will default Normal text to the specs you select. Then, when you bring text into a new document (created after you change the Normal style sheet) with AS, it will be 7 pts.
  2. You can set the text to 7 pts. by setting the paragraph properties “size” and “leading”
set every paragraph of story 1 of document 1 to {size:"7 pts.", leading:"8 pts."}
  1. Create a style (you can do this programmatically with AS) and apply that style to the text.
set style sheet of paragraph 1 of story 1 of document 1 to "My 7pt style"

You could create an entire QuarkXPress document programmatically in AS, the scripting is that powerful. The only thing that could be more masochistic is to do it in Postscript :slight_smile:
BTW, when you make a new text box at the beginning, the index is 1. It may be easier and cleaner to use that as a reference then to assign it to a variable. There would be no reason to have to select the box, just reference text box 1. And by tracking box creation with an incrementer, you can then go back to a previous box.

make new text box at beginning
make new text box at beginning --the box created above is now text box 2
make new text box at beginning
select text box 3 --gets you the first box created

I know I seem to be harping on this, but if you’re going to be scripting a lot in QuarkXPress, beg, borrow, or buy a copy of Shirley W. Hopkins’s “Applescripting QuarkXPress”. If I seem tall, it’s only because I’m standing on giants.

This code works but I would like to clean it up a little.

set boxProps to {bounds:{10,10, 110, 110}, color:null}

tell application “QuarkXPress?”
tell document 1
make new text box at beginning with properties boxProps
select text box 1
set tool mode to contents mode
paste
end tell
end tell

I want to try and do something like this any help would be great knowledge to me. I have removed the code for selecting the text box and pasting into the text box. Now take mynewtext from my clipboard and put it in the new text box that has been created. The text has already been copied to my clipboard now I just need to find a way to put it in the new text box.

tell application “finder”
activate
set mynewtext to the clipboard–get the content
end tell

set boxProps to {bounds:{10,10, 110, 110}, color:null}

tell application “QuarkXPress?”
tell document 1
make new text box at beginning with properties boxProps & mynewtext
set tool mode to contents mode

end tell
end tell

Icecold,

You don’t have to paste the text.

After you get the text off the clipboard, (where are you copying this from by the way?), use the following code to have Quark set the copy in a text box.

Try the following:

set yourText to "Whatever you want to put in the text box" as string

tell application "QuarkXPress™"
	set boxProps to {bounds:{10, 10, 110, 110}, color:null}--your bounds
	tell document 1--address whatever document you are working with
		set newTxtBox to make new text box at beginning with properties boxProps--make your text box using your properties and set a variable to it
		set story 1 of newTxtBox to yourText--set story 1 of your new text box to whatever you want it to say.
	end tell
end tell

Best regards,

Ok I have changed my code some. I am trying to tie this apple script with a project that I am creating in Realbasic 5. What I have is an Editfield in my RB project that has the text “This is a test. Lets Hope It Works.” and it is dim Qtext as a string. Then In my applescript I have passed it along as {Q}
It creates the new box with my props but my text that is passed does not get put into that textbox. Where am I going wrong

On run {Q}
set yourText to Q
tell application “QuarkXPress™”
set boxProps to {bounds:{10, 10, 110, 110}, color:null}–your bounds
tell document 1–address whatever document you are working with
make new text box at beginning with properties boxProps
set tool mode to contents mode
set story 1 of newTxtBox to yourText

end tell
end tell
End run

On run {Q}
set yourText to Q
tell application “QuarkXPress™”
set boxProps to {bounds:{10, 10, 110, 110}, color:null}–your bounds
tell document 1–address whatever document you are working with
set newTxtBox to make new text box at beginning with properties boxProps
set tool mode to contents mode
set story 1 of newTxtBox to yourText

end tell
end tell
End run
You were telling Quark to set story 1 of newTxtBox but hadn’t defined what newTxtBox is.

Try it now.

Perfect Thanks for all your help. It worked like a charm :smiley: