I made a Pixelmator Pro Library

Thanks Mark,

Here is my first version of Pixelmator Pro Script Library.

(**
* Description: Script Library for Pixelmator Pro v1.8
*
* Revisions: 1 Oct. 1/2020 - Fredrik Gustafsson
*
* Legal: For you to use, to modify or update but also to share.
*)

--~~~~~~~~~ [Documents]

(**
* Make new document with input {width,height}
* ex. my makeDocumentWithSize:{512, 512}
*)

-- my makeDocumentWithSize:{512, 512}
on makeDocumentWithSize:theSize
	tell application "Pixelmator Pro"
		set {theWidth, theHeight} to theSize
		make new document with properties {width:theWidth, height:theHeight, resolution:72}
	end tell
end makeDocumentWithSize:

(**
* Make new document from clipboard.
*)

-- makeDocumentFromClipboard()
on makeDocumentFromClipboard()
	tell application "Pixelmator Pro"
		make document from clipboard
	end tell
end makeDocumentFromClipboard

--~~~~~~~~~ [Layer]

(**
* Make new layer with name.
* ex. my makeLayerWithName:"Layer1"
*)

-- my makeLayerWithName:"Layer1"
on makeLayerWithName:theName
	tell application "Pixelmator Pro"
		set theDocument to front document
		tell theDocument to make new layer with properties {name:theName}
	end tell
end makeLayerWithName:

(**
* Duplicate a layer with name.
*)

-- my duplicateLayerWithName:"background"
on duplicateLayerWithName:theName
	tell application "Pixelmator Pro"
		set theDocument to front document
		tell theDocument to duplicate layer theName
	end tell
end duplicateLayerWithName:

(**
* Delete layer with name.
*)

-- my deleteLayerWithName:"Layer"
on deleteLayerWithName:theName
	tell application "Pixelmator Pro"
		set theDocument to front document
		tell theDocument to delete layer theName
	end tell
end deleteLayerWithName:

(**
* Select layer with name.
*)

-- my selectLayerWithName:{"Background"}
on selectLayerWithName:theName
	tell application "Pixelmator Pro"
		set theDocument to front document
		tell theDocument
			set theLayerList to its name of every layer
			set theIndex to my list_position(theName, theLayerList)
			set layerItems to select layer theIndex
		end tell
	end tell
end selectLayerWithName:

(**
* Select layers with name in range. 
*)

-- my selectLayerWithNamesFrom:"Layer" toLayerName:"Background"
on selectLayerWithNamesFrom:theLayerBegin toLayerName:theLayerEnd
	tell application "Pixelmator Pro"
		set theDocument to front document
		tell theDocument
			set theLayerList to its name of every layer
			set theIndexBegin to my list_position(theLayerBegin, theLayerList)
			set theIndexEnd to my list_position(theLayerEnd, theLayerList)
			set layerItems to select (layers theIndexBegin thru theIndexEnd)
		end tell
	end tell
end selectLayerWithNamesFrom:toLayerName:

(**
* Change currentLayerName to newLayerName.
* ex. my changeLayerNameFrom:"Layer" toLayerName:"Sun"
*)

-- my changeLayerNameFrom:"Background Layer" toLayerName:"Background"
on changeLayerNameFrom:currentLayerName toLayerName:newLayerName
	tell application "Pixelmator Pro"
		set theDocument to front document
		tell theDocument
			set theLayerList to its name of every layer
			log theLayerList
			try
				set theIndex to my list_position(currentLayerName, theLayerList)
				set name of layer (get item theIndex of theLayerList) to newLayerName
			end try
		end tell
	end tell
end changeLayerNameFrom:toLayerName:

(**
* Merge 2 layers with index
*)

-- my mergeListLayers:{1, 4}
on mergeListLayers:theList
	tell application "Pixelmator Pro"
		set theDocument to front document
		tell theDocument
			try
				merge layers {layer (item 1 of theList), layer (item 2 of theList)}
			end try
		end tell
	end tell
end mergeListLayers:

(**
* Merge visible layers.
*)

-- mergeVisibleLayers()
on mergeVisibleLayers()
	tell application "Pixelmator Pro"
		set theDocument to front document
		tell theDocument to merge visible
	end tell
end mergeVisibleLayers

(**
* Merge all layers.
*)

-- mergeAllLayers()
on mergeAllLayers()
	tell application "Pixelmator Pro"
		set theDocument to front document
		tell theDocument to merge all
	end tell
end mergeAllLayers

(**
* Replace current layer name with 
*)

-- my replaceLayerWith:"Layer" withNewLayer:"Ellipse"
on replaceLayerWith:currentLayer withNewLayer:replaceLayer
	tell application "Pixelmator Pro"
		set theDocument to front document
		tell theDocument to set layer currentLayer to layer replaceLayer
	end tell
end replaceLayerWith:withNewLayer:

--~~~~~~~~~

(**
* Draw selection object with properties with mode option
*)

-- my drawSelectionObjectWith:{30, 30, 50, 50} withMode:"Subtract"
on drawSelectionObjectWith:theRecord withMode:theOption
	tell application "Pixelmator Pro"
		set theDocument to front document
		if (theOption is not "") then
			if (theOption = "New") then
				set theOption to new selection
			end if
			if (theOption = "Add") then
				set theOption to add selection
			end if
			if (theOption = "Subtract") then
				set theOption to subtract selection
			end if
			if (theOption = "Intersect") then
				set theOption to intersect selection
			end if
		else
			error number -128
		end if
		tell theDocument to draw selection bounds theRecord mode theOption
	end tell
end drawSelectionObjectWith:withMode:

(**
* Draw elliptical selection object with properties with mode option
*)

-- set {xPos, yPos, xSize, ySize} to {50, 150, 200, 200}
-- my drawEllipticalSelectionObjectWith:{xPos, yPos, xSize, ySize} withMode:"Add"
on drawEllipticalSelectionObjectWith:theProperties withMode:theOption
	tell application "Pixelmator Pro"
		set theDocument to front document
		if (theOption is not "") then
			if (theOption = "New") then
				set theOption to new selection
			end if
			if (theOption = "Add") then
				set theOption to add selection
			end if
			if (theOption = "Subtract") then
				set theOption to subtract selection
			end if
			if (theOption = "Intersect") then
				set theOption to intersect selection
			end if
		else
			error number -128
		end if
		tell theDocument to draw elliptical selection bounds theProperties mode theOption
	end tell
end drawEllipticalSelectionObjectWith:withMode:

(**
* Invert selection of the object.
*)

-- invertSelectionObject()
on invertSelectionObject()
	tell application "Pixelmator Pro"
		set theDocument to front document
		tell theDocument to invert selection
	end tell
end invertSelectionObject

--~~~~~~~~~ [Selection Layer]

(**
* Make shape rectangle with color input.
*)

-- my makeShapeRectangleWith:{30, 30, 50, 50} withColor:{0, 0, 45000}
on makeShapeRectangleWith:theRecord withColor:theColor
	tell application "Pixelmator Pro"
		set theDocument to front document
		tell theDocument
			set theSelection to draw selection bounds theRecord
			fill current layer with color theColor
		end tell
	end tell
end makeShapeRectangleWith:withColor:

--~~~~~~~~~ [Current Layer]

(**
* Change the bounds of shape rectangle with TopLeftX: Y: bottomRightX: Y:
*)

-- my boundsShapeRectangleTopLeftX:20 Y:20 bottomRightX:60 Y:60
on boundsShapeRectangleTopLeftX:x_tl Y:y_tl bottomRightX:x_br Y:y_br
	tell application "Pixelmator Pro"
		set theDocument to front document
		tell theDocument to tell current layer
			set bounds to {x_tl, y_tl, x_br, y_br}
		end tell
	end tell
end boundsShapeRectangleTopLeftX:Y:bottomRightX:Y:

(*
* Set position of current selected layer in {x,y} as list 
* from ex. TopLeft with a rectangle shape.
*)

-- my setPositionOfCurrentLayer:{20, 10}
on setPositionOfCurrentLayer:theRecord
	tell application "Pixelmator Pro"
		set theDocument to front document
		tell theDocument to tell current layer
			set position to theRecord as list
		end tell
	end tell
end setPositionOfCurrentLayer:

(*
* Set width and height of current selected layer as list
*)

-- my setWidthHightOfCurrentLayer:{60, 65}
on setWidthHightOfCurrentLayer:theRecord
	tell application "Pixelmator Pro"
		set theDocument to front document
		tell theDocument to tell current layer
			set {width, height} to theRecord as list
		end tell
	end tell
end setWidthHightOfCurrentLayer:

(**
* Set visible of curent selected layer as boolean
*)

-- my setSelectedLayerVisible:"true"
on setSelectedLayerVisible:asBoolean
	tell application "Pixelmator Pro"
		set theDocument to front document
		tell theDocument to tell current layer
			set visible to asBoolean as boolean
		end tell
	end tell
end setSelectedLayerVisible:

(**
* Set rotation of current selected layer as integer
*)

-- my setRotationOfCurrentLayer:25
on setRotationOfCurrentLayer:theValue
	tell application "Pixelmator Pro"
		set theDocument to front document
		tell theDocument to tell current layer
			set rotation to theValue as integer
		end tell
	end tell
end setRotationOfCurrentLayer:

--~~~~~~~~~ [Style]

(**
* Set the style of blend mode
* This example use 2 blend modes normal and darken.
*)

-- my setBlendModeOfCurrentLayer:"normal"
on setBlendModeOfCurrentLayer:theValue
	tell application "Pixelmator Pro"
		set theDocument to front document
		tell theDocument to tell current layer
			if (theValue = "normal") then
				set theValue to normal
			else if (theValue = "darken") then
				set theValue to darken
			end if
			set blend mode to theValue
		end tell
	end tell
end setBlendModeOfCurrentLayer:

(**
* Set shadow color of current selected layer as list
*)

-- my setShadowColorOfCurrentLayerTo:{1000, 1000, 45000}
on setShadowColorOfCurrentLayerTo:theColor
	tell application "Pixelmator Pro"
		set theDocument to front document
		tell theDocument to tell styles of current layer
			set shadow blur to 10
			set shadow distance to 5
			set shadow angle to 180
			set shadow color to theColor as list
			set shadow opacity to 45
		end tell
	end tell
end setShadowColorOfCurrentLayerTo:

(*
* Set stroke color of current selected layer as list
*)

-- my setStrokeColorOfCurrentLayerTo:{0, 0, 35000}
on setStrokeColorOfCurrentLayerTo:theColor
	tell application "Pixelmator Pro"
		set theDocument to front document
		tell theDocument to tell styles of current layer
			set stroke width to 2
			set stroke color to theColor as list
			set stroke opacity to 75
		end tell
	end tell
end setStrokeColorOfCurrentLayerTo:

(**
* Set fill color of current selected layer as list
*)

-- my setFillColorOfCurrentLayerTo:{100, 16000, 35000}
on setFillColorOfCurrentLayerTo:theColor
	tell application "Pixelmator Pro"
		set theDocument to front document
		tell theDocument to tell styles of current layer
			set fill color to theColor as list
			set fill opacity to 75
		end tell
	end tell
end setFillColorOfCurrentLayerTo:

(*
* Set inner shadow of current selected layer as list
*)

my setInnerShadowOfCurrentLayerTo:{23000, 1000, 0}
on setInnerShadowOfCurrentLayerTo:theColor
	tell application "Pixelmator Pro"
		set theDocument to front document
		tell theDocument to tell styles of current layer
			set inner shadow blur to 10
			set inner shadow distance to 7
			set inner shadow angle to 45
			set inner shadow color to theColor as list
			set inner shadow opacity to 85
		end tell
	end tell
end setInnerShadowOfCurrentLayerTo:

--~~~~~~~~~ [Supported handlers] 

on list_position(this_item, this_list)
	repeat with i from 1 to the count of this_list
		if item i of this_list contains this_item then return i
	end repeat
	return 0
end list_position

Just present the source here in your topic. Wrap your script in three back-ticks (```) to get it presented correctly, Here’s an example:

```
set a to "world"
display alert "Hello " & a buttons {"OK"} default button 1
```

The forum will provide an Open in Script Debugger button.

1 Like

Perhaps, if we are not checking that there is a front document,
enough to reduce these incantations to:

tell front document to ...

?

Thanks, I will include that in next update.

1 Like

UPDATED: 08/10/2020
Pixelmator Pro Script Library.

Any feedback is always welcome.

Regards.
Fredrik

(**
* Description: Script Library for Pixelmator Pro v1.8
*
* Revisions: 
* 01/10/2020 - First release
* 08/10/2020 - Update the code of handlers also include new handlers.
*
*
* Legal: For you to use, modify, update and share.
* 
* The only thing I ask from you.
* (If you do change/update, share it with everyone).
*)

(**
* [Document suite]:
* 	makeDocumentWithImageSize:(list), makeDocumentFromClipboard()
*	getDocumentInfoProperties()
*)

(** 
* [Layer suite]:
*	makeLayerWithName:(string), duplicateLayerWithName:(string)
*	selectLayerWithName:(string), selectLayerWithNamesInRange:(string):toLayerName:(string)
*	deleteLayerWithName:(string), renameLayerNameFrom:(string):toLayerName:(string)
*	mergeLayersByIndex:(list), mergeLayersByVisible(), mergeLayersByAll()
*	replaceLayerByName:(string):withLayer:(string)
*)

(**
* [Selection suite]
*	convertSelectionToShape(), invertSelection(), deselectSelection(), 
*	fillSelectionByColor:(list), drawSelectionByRectangular:(list):mode:(string),
*	drawSelectionByElliptical:(list):mode:(string), resizeSelectionByBounds:(list),
*
*	positionByCurrentSelection:(list), resizeByCurrentSelection:(list),
*	rotateByCurrentSelection:(integer), boolVisibleByCurrentSelection:(boolean)	
*)

(**
* [Shape suite]:
*	makeShapeRectangleWithProperties:(string) shapeSize:(list) 
*		shapePosition:(list) layerPosition:(string) layerPosName:(string)
*
*	makeShapeRoundedRectangleWithProperties:(string) shapeSize:(list)
*		shapePosition:(list) shapeRadius:(integer) layerPosition:(string) layerPosName:(string)
* 
*	makeShapeEllipseWithProperties:(string) shapeSize:(list) 
*		shapePosition:(list) layerPosition:(string) layerPosName:(string)
*
*	makeShapePolygonWithProperties:(string) shapeSize:(list) 
*		shapePosition:(list) layerPosition:(string) layerPosName:(string)
*
*	makeShapeStarWithProperties:(string) shapeSize:(list) 
*		shapePosition:(list) shapePoints:(integer) shapeRadius:(real) 
*		layerPosition:(string) layerPosName:(string)
*)

(**
* [Style suite]:
*	blendmodeStyleInCurrentSelection:(string), shadowStyleInCurrentSelection:(list)
*	strokeStyleColorInCurrentSelection:(list), fillStyleColorInCurrentSelection:(list)
*	innerShadowStyleColorInCurrentSelection:(list)
*
*)


--- [Document suite]


(**
* [makeDocumentWithImageSize:(list)]
*
* Description: Make new document with image size {width, height}
* ex. my makeDocumentWithImageSize:{512, 512}
*)

-- my makeDocumentWithImageSize:{1024, 1024}
on makeDocumentWithImageSize:_imageSize
	tell application "Pixelmator Pro"
		try
			set {theWidth, theHeight} to _imageSize as list
			make new document with properties {width:theWidth, height:theHeight, resolution:300, bits per channel:8}
		end try
	end tell
end makeDocumentWithImageSize:

(**
* [makeDocumentFromClipboard()]
*
* Description: Make new document from clipboard.
*)

-- makeDocumentFromClipboard()
on makeDocumentFromClipboard()
	tell application "Pixelmator Pro"
		make document from clipboard
	end tell
end makeDocumentFromClipboard

(**
* [getDocumentInfoProperties()]
*
* Description: Get properties of document info of current document.
*)

-- getDocumentInfoProperties()
on getDocumentInfoProperties()
	tell application "Pixelmator Pro"
		tell front document to its properties of document info
	end tell
end getDocumentInfoProperties


--- [Layer suite]


(**
* [makeLayerWithName:(string)]
*
* Description: Make new layer with name string.
* ex. my makeLayerWithName:"Layer1"
*)

-- my makeLayerWithName:"Layer1"
on makeLayerWithName:_nameString
	tell application "Pixelmator Pro"
		tell front document to make new layer with properties {name:_nameString}
	end tell
end makeLayerWithName:

(**
* [duplicateLayerWithName:(string)]
*
* Description: Duplicate a layer with name string.
*)

-- my duplicateLayerWithName:"background"
on duplicateLayerWithName:_nameString
	tell application "Pixelmator Pro"
		tell front document to duplicate layer _nameString
	end tell
end duplicateLayerWithName:

(**
* [selectLayerWithName:(string)]
*
* Description: Select a layer with name string.
*)

-- my selectLayerWithName:"Shape"
on selectLayerWithName:_nameString
	tell application "Pixelmator Pro"
		tell front document
			set theLayerList to its name of every layer
			set theIndex to my list_position(_nameString, theLayerList)
			return (select layer theIndex)
		end tell
	end tell
end selectLayerWithName:

(**
* [selectLayerWithNamesInRange:(string):toLayerName:(string)]
*
* Select a layers with name string from top layer to bottom. 
*)

-- my selectLayerWithNamesFrom:"Shape" toLayerName:"Background Layer"
on selectLayerWithNamesFrom:_nameStringTop toLayerName:_nameStringBottom
	tell application "Pixelmator Pro"
		tell front document
			set theLayerList to its name of every layer
			set theIndexBegin to my list_position(_nameStringTop, theLayerList)
			set theIndexEnd to my list_position(_nameStringBottom, theLayerList)
			set layerItems to select (layers theIndexBegin thru theIndexEnd)
		end tell
	end tell
end selectLayerWithNamesFrom:toLayerName:

(**
* [deleteLayerWithName:(string)]
*
* Description: Delete a layer with name string.
*)

-- my deleteLayerWithName:"Shape"
on deleteLayerWithName:_nameString
	tell application "Pixelmator Pro"
		tell front document to delete layer _nameString
	end tell
end deleteLayerWithName:

(**
* [renameLayerNameFrom:(string):toLayerName:(string)]
*
* Description: Rename a layer from name string to a new name string.
*)

-- my renameLayerNameFrom:"Background Layer" toLayerName:"Background"
on renameLayerNameFrom:_nameStringCurrent toLayerName:_nameStringNew
	tell application "Pixelmator Pro"
		tell front document
			set theLayerList to its name of every layer
			try
				set theIndex to my list_position(_nameStringCurrent, theLayerList)
				set name of layer (get item theIndex of theLayerList) to _nameStringNew
			end try
		end tell
	end tell
end renameLayerNameFrom:toLayerName:

(**
* [mergeLayersByIndex:(list)]
*
* Description: Merge 2 layers by its index position. (lower index at top)
*)

-- my mergeLayersByIndex:{1, 4}
on mergeLayersByIndex:_indexInteger
	tell application "Pixelmator Pro"
		tell front document
			try
				merge layers {layer ((item 1 of _indexInteger) as integer), layer ((item 2 of _indexInteger) as integer)}
			end try
		end tell
	end tell
end mergeLayersByIndex:

(**
* [mergeLayersByVisible()]
*
* Description: Merge layers by visible.
*)

-- mergeLayersByVisible()
on mergeLayersByVisible()
	tell application "Pixelmator Pro"
		tell front document to merge visible
	end tell
end mergeLayersByVisible

(**
* [mergeLayersByAll()]
*
* Description: Merge layers by all.
*)

-- mergeLayersByAll()
on mergeLayersByAll()
	tell application "Pixelmator Pro"
		tell front document to merge all
	end tell
end mergeLayersByAll

(**
* [replaceLayerByName:(string):withLayer:(string)]
*
* Description: Replace layer by name with other layer.
*)

-- my replaceLayerByName:"Shape" withLayer:"Background"
on replaceLayerByName:_nameString withLayer:_replaceString
	tell application "Pixelmator Pro"
		tell front document to set layer _nameString to layer _replaceString
	end tell
end replaceLayerByName:withLayer:


--- [Selection suite]


(**
* [convertSelectionToShape()]
*
* Description: Convert the selection to shape
*)
-- convertSelectionToShape()
on convertSelectionToShape()
	tell application "Pixelmator Pro"
		tell front document to convert selection into shape
	end tell
end convertSelectionToShape

(**
* Invert selection of the object.
*)

-- invertSelectionObject()
on invertSelectionObject()
	tell application "Pixelmator Pro"
		tell front document to invert selection
	end tell
end invertSelectionObject

(*
* [deselectSelection()]
*
* Description: Deselect the selection of the object.
*)

-- deselectSelection()
on deselectSelection()
	tell application "Pixelmator Pro"
		tell front document to deselect
	end tell
end deselectSelection

(**
* [fillSelectionByColor:(list)]
*
* Description: Fill the selection by color
*)

-- my fillSelectionByColor:{2400, 35000, 0}
on fillSelectionByColor:_inputColor
	tell application "Pixelmator Pro"
		tell front document
			fill current layer with color _inputColor
		end tell
	end tell
end fillSelectionByColor:

(**
* [drawSelectionByRectangular:(list):mode:(string)]
*
* Description: Draw rectangular selection object with mode.
* [New], [Add], [Substract] and [Intersect]
*)

-- my drawSelectionByRectangular:{270, 170, 50, 50} mode:"Add"
on drawSelectionByRectangular:_inputBounds mode:_modeString
	tell application "Pixelmator Pro"
		if (_modeString is not "") then
			if (_modeString = "New") then
				set modeString to new selection
			end if
			if (_modeString = "Add") then
				set modeString to add selection
			end if
			if (_modeString = "Subtract") then
				set modeString to subtract selection
			end if
			if (_modeString = "Intersect") then
				set modeString to intersect selection
			end if
		else
			error number -128
		end if
		tell front document to draw selection bounds _inputBounds mode modeString
	end tell
end drawSelectionByRectangular:mode:

(**
* [drawSelectionByElliptical:(list):mode:(string)]
*
* Description: Draw elliptical selection object with mode.
*)

-- my drawSelectionByElliptical:{200, 150, 200, 200} mode:"Add"
on drawSelectionByElliptical:_inputBounds mode:_modeString
	tell application "Pixelmator Pro"
		if (_modeString is not "") then
			if (_modeString = "New") then
				set modeString to new selection
			end if
			if (_modeString = "Add") then
				set modeString to add selection
			end if
			if (_modeString = "Subtract") then
				set modeString to subtract selection
			end if
			if (_modeString = "Intersect") then
				set modeString to intersect selection
			end if
		else
			error number -128
		end if
		tell front document to draw elliptical selection bounds _inputBounds mode modeString
	end tell
end drawSelectionByElliptical:mode:


(**
* [resizeSelectionByBounds:(list)]
*
* Description: Resize the bounds with
*	coordinate {TopLeft_X:integer, Y:integer, bottomRight_X:integer, Y:integer}
*)

-- my resizeSelectionByBounds:{200, 200, 400, 400}
on resizeSelectionByBounds:_theRecord
	tell application "Pixelmator Pro"
		tell front document to tell current layer
			set bounds to _theRecord
		end tell
	end tell
end resizeSelectionByBounds:

(*
* [positionByCurrentSelection:(list)]
*
* Description: Position of the selection of current selected layer in {x,y} as list 
*	coordinate {TopLeft_X:integer,TopLeft_Y:integer}
*)

-- my positionByCurrentSelection:{300, 300}
on positionByCurrentSelection:_theRecord
	tell application "Pixelmator Pro"
		tell front document to tell current layer
			set position to _theRecord as list
		end tell
	end tell
end positionByCurrentSelection:

(*
* [resizeByCurrentSelection:(list)]
*
* Description: Resize the selection of current selected layer as list
*)

-- my resizeByCurrentSelection:{150, 150}
on resizeByCurrentSelection:_theRecord
	tell application "Pixelmator Pro"
		tell front document to tell current layer
			set {width, height} to _theRecord as list
		end tell
	end tell
end resizeByCurrentSelection:

(**
* [boolVisibleByCurrentSelection:(boolean)]
*
* Description: Set the boolean value of visible of curent selected layer.
*)

-- my boolVisibleByCurrentSelection:true
on boolVisibleByCurrentSelection:_Boolean
	tell application "Pixelmator Pro"
		tell front document to tell current layer
			set visible to _Boolean as boolean
		end tell
	end tell
end boolVisibleByCurrentSelection:

(**
* [rotateByCurrentSelection:(integer)]
*
* Description: Rotation of the selection of current selected layer as integer 
*)

-- my rotateByCurrentSelection:25
on rotateByCurrentSelection:_rotateInteger
	tell application "Pixelmator Pro"
		tell front document to tell current layer
			set rotation to _rotateInteger as integer
		end tell
	end tell
end rotateByCurrentSelection:


--- [Shape suite]


(**
* [makeShapeRectangleWithProperties:(string):shapeSize:(list):shapePosition:(list):layerPosition:(string):layerPosName:(string)]
*
* Description: Make shape rectangle with properties in 4 type of layer position 
* ([begin] and [end] do not use layerPosName) [before] and [after]
*)
-- my makeShapeRectangleWithProperties:"Rect1" shapeSize:{100, 100} shapePosition:{350, 200} layerPosition:"end" layerPosName:""
on makeShapeRectangleWithProperties:_shapeName shapeSize:_Size shapePosition:_Pos layerPosition:_layerPosition layerPosName:_layerPosName
	tell application "Pixelmator Pro"
		tell front document
			try
				set {theWidth, theHeight} to _Size as list
				set theProperties to {name:_shapeName, position:_Pos as list, width:theWidth, height:theHeight}
				
				if (_layerPosName is "") then -- we do not use layerPosName.
					if (_layerPosition is "begin") then
						make new rectangle shape layer at the beginning of layers with properties theProperties
					end if
					if (_layerPosition is "end") then
						make new rectangle shape layer at the end of layers with properties theProperties
					end if
				end if
				if (_layerPosition is "before") then
					make new rectangle shape layer at before layer _layerPosName with properties theProperties
				end if
				if (_layerPosition is "after") then
					make new rectangle shape layer at after layer _layerPosName with properties theProperties
				end if
			end try
		end tell
	end tell
end makeShapeRectangleWithProperties:shapeSize:shapePosition:layerPosition:layerPosName:

(**
* [makeShapeRoundedRectangleWithProperties:(string):shapeSize:(list):shapePosition:(list):layerPosition:(string):layerPosName:(string)]
*
* Description: Make shape rounded rectangle with properties in 4 type of layer position 
* ([begin] and [end] do not use layerPosName) [before] and [after]
*)
-- my makeShapeRoundedRectangleWithProperties:"roundedRect2" shapeSize:{200, 200} shapePosition:{200, 100} shapeRadius:35 layerPosition:"begin" layerPosName:""
on makeShapeRoundedRectangleWithProperties:_shapeName shapeSize:_Size shapePosition:_Pos shapeRadius:_Radius layerPosition:_layerPosition layerPosName:_layerPosName
	tell application "Pixelmator Pro"
		tell front document
			try
				set {theWidth, theHeight} to _Size as list
				set theProperties to {name:_shapeName, position:_Pos as list, width:theWidth, height:theHeight, corner radius:_Radius as integer}
				
				if (_layerPosName is "") then -- we do not use layerPosName.
					if (_layerPosition is "begin") then
						make new rounded rectangle shape layer at the beginning of layers with properties theProperties
					end if
					if (_layerPosition is "end") then
						make new rounded rectangle shape layer at the end of layers with properties theProperties
					end if
				end if
				if (_layerPosition is "before") then
					make new rounded rectangle shape layer at before layer _layerPosName with properties theProperties
				end if
				if (_layerPosition is "after") then
					make new rounded rectangle shape layer at after layer _layerPosName with properties theProperties
				end if
			end try
		end tell
	end tell
end makeShapeRoundedRectangleWithProperties:shapeSize:shapePosition:shapeRadius:layerPosition:layerPosName:

(**
* [makeShapeEllipseWithProperties:(string):shapeSize:(list):shapePosition:(list):layerPosition:(string):layerPosName:(string)]
*
* Description: Make shape ellipse with properties in 4 type of layer position 
* ([begin] and [end] do not use layerPosName) [before] and [after]
*)
-- my makeShapeEllipseWithProperties:"Shape1" shapeSize:{100, 100} shapePosition:{300, 200} layerPosition:"begin" layerPosName:""
on makeShapeEllipseWithProperties:_shapeName shapeSize:_Size shapePosition:_Pos layerPosition:_layerPosition layerPosName:_layerPosName
	tell application "Pixelmator Pro"
		tell front document
			try
				set {theWidth, theHeight} to _Size as list
				set theProperties to {name:_shapeName, position:_Pos as list, width:theWidth, height:theHeight}
				
				if (_layerPosName is "") then -- we do not use layerPosName.
					if (_layerPosition is "begin") then
						make new ellipse shape layer at the beginning of layers with properties theProperties
					end if
					if (_layerPosition is "end") then
						make new ellipse shape layer at the end of layers with properties theProperties
					end if
				end if
				if (_layerPosition is "before") then
					make new ellipse shape layer at before layer _layerPosName with properties theProperties
				end if
				if (_layerPosition is "after") then
					make new ellipse shape layer at after layer _layerPosName with properties theProperties
				end if
			end try
		end tell
	end tell
end makeShapeEllipseWithProperties:shapeSize:shapePosition:layerPosition:layerPosName:

(**
* [makeShapePolygonWithProperties:(string):shapeSize:(list):shapePosition:(list):layerPosition:(string):layerPosName:(string)]
*
* Description: Make shape polygon with properties in 4 type of layer position 
* ([begin] and [end] do not use layerPosName) [before] and [after]
*)

-- my makeShapePolygonWithProperties:"Poly" shapeSize:{200, 200} shapePosition:{200, 200} layerPosition:"begin" layerPosName:""
on makeShapePolygonWithProperties:_shapeName shapeSize:_Size shapePosition:_Pos layerPosition:_layerPosition layerPosName:_layerPosName
	tell application "Pixelmator Pro"
		tell front document
			try
				set {theWidth, theHeight} to _Size as list
				set theProperties to {name:_shapeName, position:_Pos as list, width:theWidth, height:theHeight}
				
				if (_layerPosName is "") then -- we do not use layerPosName.
					if (_layerPosition is "begin") then
						make new polygon shape layer at the beginning of layers with properties theProperties
					end if
					if (_layerPosition is "end") then
						make new polygon shape layer at the end of layers with properties theProperties
					end if
				end if
				if (_layerPosition is "before") then
					make new polygon shape layer at before layer _layerPosName with properties theProperties
				end if
				if (_layerPosition is "after") then
					make new polygon shape layer at after layer _layerPosName with properties theProperties
				end if
			end try
		end tell
	end tell
end makeShapePolygonWithProperties:shapeSize:shapePosition:layerPosition:layerPosName:

(**
* [makeShapeStarWithProperties:(string):shapeSize:(list):shapePosition:(list):shapePoints:(integer):shapeRadius:(real):layerPosition:(string):layerPosName:(string)]
*
* Description: Make shape polygon with properties in 4 type of layer position 
* ([begin] and [end] do not use layerPosName) [before] and [after]
*)

-- my makeShapeStarWithProperties:"Star23" shapeSize:{200, 200} shapePosition:{200, 200} shapePoints:6 shapeRadius:75 layerPosition:"begin" layerPosName:""
on makeShapeStarWithProperties:_shapeName shapeSize:_Size shapePosition:_Pos shapePoints:_pointsInteger shapeRadius:_inputRadius layerPosition:_layerPosition layerPosName:_layerPosName
	tell application "Pixelmator Pro"
		tell front document
			try
				set {theWidth, theHeight} to _Size as list
				set theProperties to {name:_shapeName, position:_Pos as list, width:theWidth, height:theHeight, star points:_pointsInteger, star radius:_inputRadius}
				
				
				if (_layerPosName is "") then -- we do not use layerPosName with 'begin' and 'end'
					if (_layerPosition is "begin") then
						make new star shape layer at the beginning of layers with properties theProperties
					end if
					if (_layerPosition is "end") then
						make new star shape layer at the end of layers with properties theProperties
					end if
				end if
				if (_layerPosition is "before") then
					make new star shape layer at before layer _layerPosName with properties theProperties
				end if
				if (_layerPosition is "after") then
					make new star shape layer at after layer _layerPosName with properties theProperties
				end if
			end try
		end tell
	end tell
end makeShapeStarWithProperties:shapeSize:shapePosition:shapePoints:shapeRadius:layerPosition:layerPosName:


--- [Style suite]


(**
* [blendmodeStyleInCurrentSelection:(string)]
*
* Description: Set the style of blend mode of current selection layer.
*)

-- my blendmodeStyleInCurrentSelection:"normal"
on blendmodeStyleInCurrentSelection:_nameString
	tell application "Pixelmator Pro"
		tell front document to tell current layer
			if (_nameString is not "") then
				try
					if (_nameString = "normal") then
						set nameString to normal
					end if
					if (_nameString = "darken") then
						set nameString to darken
					end if
					if (_nameString = "multiply") then
						set nameString to multiply
					end if
					if (_nameString = "color burn") then
						set nameString to color burn
					end if
					if (_nameString = "linear burn") then
						set nameString to linear burn
					end if
					if (_nameString = "darker color") then
						set nameString to darker color
					end if
					if (_nameString = "lighten") then
						set nameString to lighten
					end if
					if (_nameString = "screen") then
						set nameString to screen
					end if
					if (_nameString = "color dodge") then
						set nameString to color dodge
					end if
					if (_nameString = "linear dodge") then
						set nameString to linear dodge
					end if
					if (_nameString = "lighter color") then
						set nameString to lighter color
					end if
					if (_nameString = "overlay") then
						set nameString to overlay
					end if
					if (_nameString = "soft light") then
						set nameString to soft light
					end if
					if (_nameString = "hard light") then
						set nameString to hard light
					end if
					if (_nameString = "vivid light") then
						set nameString to vivid light
					end if
					if (_nameString = "linear light") then
						set nameString to linear light
					end if
					if (_nameString = "pin light") then
						set nameString to pin light
					end if
					if (_nameString = "hard mix") then
						set nameString to hard mix
					end if
					if (_nameString = "difference") then
						set nameString to difference
					end if
					if (_nameString = "exclusion") then
						set nameString to exclusion
					end if
					if (_nameString = "substract") then
						set nameString to substract
					end if
					if (_nameString = "divide") then
						set nameString to divide
					end if
					if (_nameString = "hue") then
						set nameString to hue blend mode
					end if
					if (_nameString = "saturation") then
						set nameString to saturation blend mode
					end if
					if (_nameString = "color") then
						set nameString to color blend mode
					end if
					if (_nameString = "luminosity") then
						set nameString to luminosity
					end if
					if (_nameString = "pass through") then
						set nameString to pass through
					end if
					if (_nameString = "behind") then
						set nameString to behind blend mode
					end if
					set blend mode to nameString
				end try
			else
				log "error: " & "Check if blend mode string is correct."
				error number -128
			end if
		end tell
	end tell
end blendmodeStyleInCurrentSelection:

(**
* [shadowStyleInCurrentSelection:(list)]
*
* Description: Set the style of shadow color of current selected layer 
*		with default options.
*)

-- my shadowStyleColorInCurrentSelection:{1000, 1000, 45000}
on shadowStyleColorInCurrentSelection:_inputColor
	tell application "Pixelmator Pro"
		tell front document to tell styles of current layer
			set shadow blur to 6
			set shadow distance to 3
			set shadow angle to 315
			set shadow color to _inputColor as list
			set shadow opacity to 40
		end tell
	end tell
end shadowStyleColorInCurrentSelection:

(*
* [strokeStyleColorInCurrentSelection:(list)]
*
* Description: Set the style of stroke color of current selected layer
*		with default options.
*)

-- my strokeStyleColorInCurrentSelection:{0, 0, 35000}
on strokeStyleColorInCurrentSelection:_inputColor
	tell application "Pixelmator Pro"
		tell front document to tell styles of current layer
			set stroke width to 2
			set stroke position to center -- inside, center or outsie
			set stroke type to line -- line, dash or dot
			set stroke color to _inputColor as list
			set stroke opacity to 75
		end tell
	end tell
end strokeStyleColorInCurrentSelection:

(**
* [fillStyleColorInCurrentSelection:(list)]
*
* Description: Set the style of fill color of current selected layer
* 		with default options.
*)

-- my fillStyleColorInCurrentSelection:{1000, 36000, 20000}
on fillStyleColorInCurrentSelection:_inputColor
	tell application "Pixelmator Pro"
		tell front document to tell styles of current layer
			set fill color to _inputColor as list
			set fill opacity to 100
		end tell
	end tell
end fillStyleColorInCurrentSelection:

(*
* [innerShadowStyleColorInCurrentSelection:(list)]
*
* Description: Set the style of inner shadow color of current selected layer
*		with default options.
*)

-- my innerShadowStyleColorInCurrentSelection:{1000, 10000, 1000}
on innerShadowStyleColorInCurrentSelection:_inputColor
	tell application "Pixelmator Pro"
		tell front document to tell styles of current layer
			set inner shadow blur to 5
			set inner shadow distance to 3
			set inner shadow angle to 315
			set inner shadow color to _inputColor as list
			set inner shadow opacity to 85
		end tell
	end tell
end innerShadowStyleColorInCurrentSelection:


--~~~~~~~~~ [Supported handlers] 


on list_position(this_item, this_list)
	repeat with i from 1 to the count of this_list
		if item i of this_list contains this_item then return i
	end repeat
	return 0
end list_position

This is amazing!!! Do you have a newer version of this library?

Thanks, Yes I do… but its not ready for release…

What are you missing ??

If you have done anything with my code, share your experience.