This should be so simple but my quark scripting skills are not to good.
How do you centre a picture in its box with applescript. I have seen how to do it in scriptmaster but it seems you need the scriptmaster extension to use this command.
Cheers for any help in advance
Steve
I just whipped this up, so it hasn’t had extensive testing, but it seems to work:
tell application "QuarkXPress™ 4.11"
tell document 1
set theBox to the selection
my centerTheBox(theBox)
end tell
end tell
on centerTheBox(whichBox)
tell application "QuarkXPress™ 4.11"
tell document 1
-- rudimentary checks
if box type of whichBox is not picture box type then
return
else if bounds of image 1 of whichBox = {0, 0, 0, 0} then
return
end if
-- set up
set {oldVert, oldHoriz, vertical measure, horizontal measure} to ¬
{vertical measure, horizontal measure, points, points}
set {oldTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ""}
tell whichBox
-- get natural center of image
set imageBounds to (bounds of image 1)
set imageWidth to (item 3 of imageBounds as real) - (item 2 of imageBounds as real)
set imageCenterHorizontal to (imageWidth / 2)
set imageHeight to (item 4 of imageBounds as real) - (item 1 of imageBounds as real)
set imageCenterVertical to (imageHeight / 2)
-- adjust for scale
set imageScale to scale of image 1 as list
set imageCenterVertical to ((imageCenterVertical * (item 1 of imageScale as real)) / 100)
set imageCenterHorizontal to ((imageCenterHorizontal * (item 2 of imageScale as real)) / 100)
-- adjust for offset
set imageOffset to offset of image 1 as list
set imageOffset to {(item 1 of imageOffset as real), (item 2 of imageOffset as real)}
set imageCenterHorizontal to (imageCenterHorizontal + (item 2 of imageOffset))
set imageCenterVertical to (imageCenterVertical + (item 1 of imageOffset))
-- get center of box
set boxHeight to height of bounds as real
set boxCenterVertical to (boxHeight / 2)
set boxWidth to width of bounds as real
set boxCenterHorizontal to (boxWidth / 2)
-- figure difference
set imageOffVert to boxCenterVertical - imageCenterVertical
set imageOffHoriz to boxCenterHorizontal - imageCenterHorizontal
-- move image
set offset of image 1 to {((item 1 of imageOffset) + imageOffVert), ((item 2 of imageOffset) + imageOffHoriz)}
end tell
-- clean up
set {vertical measure, horizontal measure, AppleScript's text item delimiters} to {oldVert, oldHoriz, oldTID}
end tell
end tell
end centerTheBox
–tet
On the off chance you don’t know: Command-Shift-M does the same thing.
–tet
You think? Sheesh.
–tet
Below is an easier solution, I think, than Tet’s. It is akin to using the CMD-Sft-M only in AppleScript.
tell application "QuarkXPress™ 4.11 2400"
activate
tell document 1
tell page 1
tell first picture box
tell image 1 ----- Important line is below
set bounds to centered -----Important Line is above
end tell --Image 1
end tell --PB
end tell --page 1
end tell --doc 1
end tell --Quark
Try these special properties of image objects:
tell application "QuarkXPress™ 4.11"
--to center image in box
set bounds of image of current box to centered
--to center and scale to fit
set bounds of image 1ofcurrent box to exact fit
--to center and scale proportionally to fit
set bounds of image 1of current box to proportional fit
end tell
Often when I work with the bounds of an image object I find that AppleScript returns incorrect values, ie; ‘bounds of image 1’ do not always equal the acutal image bounds. It’s a pesky bug because it depends on what type of image it is (EPS pics seem to always be accurate, but TIFF pics are off sometimes by as much as 15 pts).
I just discovered a second property of the image object in Quark’s dictionary. The ‘bounds’ property is read-only, but there’s another ‘bounds’ property that allows setting certain properties of the image offset and scale all in one line:
tell application "QuarkXPress™ 4.11"
--to center image in box
set bounds of image 1 of current box to centered
--to center and scale to fit
set bounds of image 1 of current box to exact fit
--to center and scale proportionally to fit
set bounds of image 1 of current box to proportional fit
end tell