Bospoking Scripts?

Discuss AppleScripting for QuarkXPress 10, 9 & 8 (and before)
Jean-Marie Schwartz
Posts: 1174
Joined: 23 Nov 2004, 04:30

Bospoking Scripts?

Post by Jean-Marie Schwartz » 22 Dec 2012, 06:47

Rakesh Solanki wrote:I get a lot of syntax errors
Thats odd. The piece of script Ive posted shows clearly mine has compiled OK so no syntax error at all. Or do mean errors at runn time?

Rakesh Solanki
Posts: 0
Joined: 18 Dec 2012, 15:35

Bospoking Scripts?

Post by Rakesh Solanki » 02 Jan 2013, 21:16

Happy New Year - this is how I've started the script as per your suggestion:tell application "QuarkXPress"tell document 1set TheBoxes to object reference of every picture box whose selected is truerepeat with TheBox in TheBoxestell TheBoxif box type is not picture box type or file path of image 1 is null then error "Please select a single picture box containing an image."set theID to uniqueIDend telltry-- This line will ensure that a document is open, before proceedingif not (exists document 1) then error "No document is open."but as I compile it I get a prompt stating 'Expected "end" but found "end tell".Rak

Emma
Posts: 657
Joined: 07 Jul 2004, 08:43

Bospoking Scripts?

Post by Emma » 02 Jan 2013, 22:10

Hi Rakesh,
Excuse my butting in here, I haven't followed the whole discussion. But make sure every 'tell' in your script has an 'end tell'. Also you have a 'repeat' but no 'end repeat'.
What are 'theID' and 'uniqueID'?
Also you need to put the test for open document at the beginning. I still don't understand what your script is for, but this at least compiles:
tell application "QuarkXPress"
if not (exists document 1) then
error "No document is open."
else
tell document 1
set TheBoxes to object reference of every picture box whose selected is true
repeat with TheBox in TheBoxes
tell TheBox
if box type is not picture box type or file path of image 1 is null then error "Please select a single picture box containing an image."
set theID to uniqueID
end tell
end repeat
end tell
end if
end tell

Jean-Marie Schwartz
Posts: 1174
Joined: 23 Nov 2004, 04:30

Bospoking Scripts?

Post by Jean-Marie Schwartz » 02 Jan 2013, 22:31

Hi Emma! Your code compiles on my side too. The variable theID is supposed to welcome the uniqueID of the box being processed by the loop. As such here in the code it seems to be totally useless but I can't remember either the head of the discussion. I should reread it and understand what it is for.
Rakesh, the error you got is simply because you strated an if statement and never ended it. To add to what Emma said, every tell, try, if, repeat, script and maybe some more statements must be ended accordingly and in reverse of their entry in the script (the indents should help you seeing better the relationship between them all). HTH.

Rakesh Solanki
Posts: 0
Joined: 18 Dec 2012, 15:35

Bospoking Scripts?

Post by Rakesh Solanki » 04 Jan 2013, 02:58

Hi guys. I'm new to all of this and it is like learning a new language so all the help I can get is gratefully appreciated.
I must be doing something very wrong because I cant get the script to compile at all no matter how I adapt it.
What I'm trying to do is adapt this script for placing names of selected picture boxes so that rather than selecting the boxes one at a time,I can select multiple boxes on a page and run the script once - it'd be so helpful.

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
-- This line will display an error if the current page is a master page
if masterdoc is true then [b]error "This script doesn't work on master pages."

-- This section will ensure that a single text box is selected
if not (exists current box) then error "Please select a single picture box containing an image."tell current boxif box type is not picture box type or file path of image 1 is null then error "Please select a single picture box containing an image."set theID to uniqueIDend tell-- This section configures variables that will be used later in the scriptset pagenumber to get the page number of page 1 of the generic box id theIDif pagenumber > 2000 then error "This script does not work with pasteboard items."set flag to trueset boxNum to the index of generic box id theID-- This line will store the name property of the selected imageset imageName to name of image 1 of generic box id theID-- This section will get the file path of the selected imageset pathName to file path of image 1 of generic box id theID as textif pathName is no disk file then--this means the image is an embedded PICT file with no file pathset fileName to "Embedded PICT"set flag to falseend if-- This section will set the measurement units for the document to pointsset hm to horizontal measureset vm to vertical measureset horizontal measure to pointsset vertical measure to points-- This section will isolate the bound properties of the selected picture box-- The boxes bounds read as {A,B,C,D}set boxBounds to bounds of generic box id theID as listset BoxA to ((top of bounds of generic box id theID) as point units) as realset BoxB to ((left of bounds of generic box id theID) as point units) as realset BoxC to ((bottom of bounds of generic box id theID) as point units) as realset BoxD to ((right of bounds of generic box id theID) as point units) as realset boxOffset to 6set boxHeight to ((size of character spec 1) as real) * 1.12-- This section will parse the images file path to obtain the images file nametryif flag is true thenset olddelims to text item delimiters of AppleScript --puts the current delimiters into a variableset text item delimiters of AppleScript to {":"} --uses the colon as the new delimiterset fileName to last text item of pathName --asks for the last item of the delimited text string and sets it to variableset text item delimiters of AppleScript to olddelims --resets the old delimitersend ifon error errmsg number errnumtryset text item delimiters of AppleScript to olddelimsset horizontal measure to hmset vertical measure to vmend tryerror errmsg number errnumend try-- This section will create the text box and add the images name and/or file nametrytell page pagenumberset nameBox to make new text box at before generic box id theID with properties {bounds:{BoxC + boxOffset, BoxB, BoxC + boxHeight + boxOffset, BoxD}, runaround:none runaround, vertical justification:top justified, color:null}set class STDR of story 1 of nameBox to falseif name of image 1 of generic box id theID is not "" thenset story 1 of nameBox to "" & imageName & ", " & fileNameelseset story 1 of nameBox to fileNameend ifset justification of paragraph 1 of story 1 of nameBox to centeredset font of story 1 of nameBox to "GillSans Light"set size of story 1 of nameBox to "9pt"end tellif box overflows of nameBox is true thenrepeat until box overflows of nameBox is falselog boxHeightset boxHeight to boxHeight + boxHeightset height of bounds of nameBox to boxHeightend repeatend ifon error errmsg number errnumset horizontal measure to hmset vertical measure to vmerror errmsg number errnumend try-- This section will reset the measurement units to their original valuesset horizontal measure to hmset vertical measure to vm-- The following beep will provide feedback of script completionbeep 2end tellon error errmsg number errnumif errnum -128 thenbeepdisplay dialog errmsg & " [" & errnum & "]" buttons {"OK"} default button 1 with icon stopend if-- For compatibility with non-US English operating systemsreturnend tryend tell

Jean-Marie Schwartz
Posts: 1174
Joined: 23 Nov 2004, 04:30

Bospoking Scripts?

Post by Jean-Marie Schwartz » 04 Jan 2013, 04:39

I didn't post the entire code! So just replace the first lines till the first occurrence of end tell in your code and replace with the code I posted some days ago. Is it clearer? (See the line set theID to uniqueID? it's the common line, so erase everything up it and paste what I posted).

Rakesh Solanki
Posts: 0
Joined: 18 Dec 2012, 15:35

Bospoking Scripts?

Post by Rakesh Solanki » 07 Jan 2013, 03:39

Hi again, I've done exactly as you stated and I'm still getting this error:
Expected "end" but found "emd tell"
???
Rak

Jean-Marie Schwartz
Posts: 1174
Joined: 23 Nov 2004, 04:30

Bospoking Scripts?

Post by Jean-Marie Schwartz » 07 Jan 2013, 04:47

Rakesh Solanki wrote:Hi again, I've done exactly as you stated and I'm still getting this error:
Expected "end" but found "emd tell"
???
Rak
A typo?

Post Reply

Return to “QuarkXPress 8, 9 & 10: AppleScript”