- Select a corner (top/bottom, left/right)
- Select vertical or horizontal stacking
- Enter stacking offset
Selected layers are stacked in the corner.
tell application "Pixelmator Pro"
tell its front document
-- Prompt for which corner to use
set dlgY to (display dialog "Select Top/Bottom:" buttons {"Top", "Bottom"} default button 1)
set dlgX to (display dialog "Select Left/Right:" buttons {"Left", "Right"} default button 1)
set userLocY to (button returned of dlgY)
set userLocX to (button returned of dlgX)
set userLoc to userLocY & userLocX
set x_prop_offset to 0 -- % x position offset between selected layers
set y_prop_offset to 0 -- % y position offset between selected layers
-- Get selected layers and unpack one level of selected groups
set sel_lays to selected layers
set sel_lay to {}
set counter to 0
repeat with clay in sel_lays
if (class of clay) is group layer then
set lays to layers of clay
else
set lays to {clay}
end if
repeat with lay in lays
copy lay to the end of sel_lay
end repeat
end repeat
-- Prompt for vertical spacing relative to the height of the first layer
if (count of sel_lay) is greater than 1 then
set userOrient to (button returned of (display dialog "Select stacking orientation:" buttons {"Vertical", "Horizontal"} default button 1))
if userOrient is "Vertical" then
set spacingPrompt to "Enter offset as % height of adjacent layer:"
else
set spacingPrompt to "Enter offset as % width of adjacent layer:"
end if
repeat
set dialogResult to (display dialog spacingPrompt default answer "100")
try
set userNumber to (text returned of dialogResult) as integer
exit repeat
end try
display dialog "Needs a valid integer." buttons {"Enter again", "Cancel"} default button 1
end repeat
if userOrient is "Vertical" then
set y_prop_offset to userNumber
else
set x_prop_offset to userNumber
end if
end if
-- Set the stack
repeat with i from 1 to count of sel_lay
set lay to item i of sel_lay
if i is greater than 1 then
-- set location of stacked layers realtive to each other
set prev to item (i - 1) of sel_lay
set prev_pos to position of prev
set x_offset to (x_prop_offset * (width of prev)) / 100
set y_offset to (y_prop_offset * (height of prev)) / 100
if userLocX is "Left" then
set xloc to x_offset + (item 1 of prev_pos)
else
set xloc to -x_offset + (item 1 of prev_pos)
end if
if userLocY is "Top" then
set yloc to y_offset + (item 2 of prev_pos)
else
set yloc to -y_offset + (item 2 of prev_pos)
end if
set position of lay to {xloc, yloc}
else
-- set location according to user prompt
if userLoc = "TopLeft" then
set position of lay to {0, 0}
else if userLoc = "TopRight" then
set position of lay to {0 + (width) - (width of lay), 0}
else if userLoc = "BottomLeft" then
set position of lay to {0, 0 + (height) - (height of lay)}
else if userLoc = "BottomRight" then
set position of lay to {0 + (width) - (width of lay), 0 + (height) - (height of lay)}
end if
end if
end repeat
end tell
end tell