alignDuplicate 'top','bottom','left' and 'right' in Pixelmator Pro

Beta version of alignDuplicate ‘top’,‘bottom’,‘left’ and ‘right’ in Pixelmator Pro
The approach is to get a mirror of the shape.

I’m welcome for a better version, so do not be shy… :slight_smile:

Make a shape layer and select the layer… run the script…

ex. alignDuplicate:“bottom”

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "JavaScriptCore"
use scripting additions

(**
* [alignDuplicate:(string)]
*)
on alignDuplicate:_align
	tell application "Pixelmator Pro"
		tell front document to tell current layer
			set theName to its name
			set {theWidth, theHeight} to {width, height}
			set {xPos, yPos} to position
		end tell
		
		-- Align to left edge of flip horizontally with duplicate.
		if (_align = "left") then
			set alignLeftEdge to {xPos - (my doJsMath("abs", theWidth)), yPos}
			tell front document to duplicate layer theName
			tell front document to tell current layer
				flip horizontally
				set position to alignLeftEdge
			end tell
		end if
		
		-- Align to right edge of flip horizontally with duplicate.
		if (_align = "right") then
			set alignRightEdge to {xPos + (my doJsMath("abs", theWidth)), yPos}
			tell front document to duplicate layer theName
			tell front document to tell current layer
				flip horizontally
				set position to alignRightEdge
			end tell
		end if
		
		-- Align to top edge of flip horizontally with duplicate.
		if (_align = "top") then
			set alignRightEdge to {xPos, yPos - (my doJsMath("abs", theHeight))}
			tell front document to duplicate layer theName
			tell front document to tell current layer
				flip horizontally
				set position to alignRightEdge
			end tell
		end if
		
		-- Align to bottom edge of flip horizontally with duplicate.
		if (_align = "bottom") then
			set alignRightEdge to {xPos, yPos + (my doJsMath("abs", theHeight))}
			tell front document to duplicate layer theName
			tell front document to tell current layer
				flip horizontally
				set position to alignRightEdge
			end tell
		end if
	end tell
end alignDuplicate:

on doJsMath(theMethod, argsList)
	if class of argsList is not list then set argsList to {argsList}
	set theContext to current application's JSContext's new()
	set theMathObject to theContext's objectForKeyedSubscript:"Math"
	return (theMathObject's invokeMethod:theMethod withArguments:argsList)'s toDouble()
end doJsMath