AppleScript to move by non-pixel units

Talk about Pixelmator Pro, share tips & tricks, tutorials, and other resources.
User avatar

2023-01-16 20:03:36

I'm trying to write some AppleScript to copy an item and move it by a regular unit of measure (1 inch or 6cm, for example). However, if I put in anything besides a number (corresponding to pixel value), I get an error:
execution error: Pixelmator Pro got an error: Can’t make {"4cm", 533} into type point. (-1700)
Here's the script I'm trying:
tell application "Pixelmator Pro"
tell the front document
set l to get current layer
tell l
  set {coordX, coordY} to position
  duplicate
  # set the position to {coordX + 280, coordY}
  set the position to {coordX + 720, coordY}
end tell
end tell
end tell
User avatar

2023-01-17 09:20:42

Unfortunately AppleScript only accepts pixels as the default measurement units, so simply adding "cm" at the end of a number won't work. A possible workaround would be to calculate exactly how many pixels are 1 cm at your document's resolution (pixels per inch), then assign that value to a custom variable that would represent 1cm at the beginning of your script and use multiples of it in place of pixel values.
User avatar

2023-01-18 21:46:49

Great, I can use the
resolution
property of
document
, then divide by 2.54:
set ppc to resolution / 2.54
.

Thanks!