Swap position {x,y} of 2 selected layers in Pixelmator Pro

Pixelmator Pro script to swap position of 2 selected layers.

Does anyone on this forum use Pixelmator Pro ??

(**
* [swapLayerWithPosition]
*
* Description: Select 2 layers to swap position.
*)

-- swapLayerWithPosition()
on swapLayerWithPosition()
	tell application "Pixelmator Pro"
		-- Get the name of every layer.
		tell front document to set theLayerList to its name of every layer
		-- Get the selected layer id.
		tell front document to set selectedLayer to its selected layers
		
		-- Get the name of selected layers.
		set selectedList to {}
		repeat with i from 1 to (count selectedLayer)
			tell item i of selectedLayer to set theName to its name
			copy theName to end of selectedList
		end repeat
		
		-- Check that we have 2 selected layers.
		if ((count selectedLayer) = 2) then
			
			-- Build the layer index of selection.
			set layerIndexList to {}
			repeat with i from 1 to (count selectedList)
				set layerItem to my list_position(item i of selectedList, theLayerList)
				copy layerItem to end of layerIndexList
			end repeat
			
			set positionList to {}
			repeat with i from 1 to 2
				tell front document to set thePosition to position of layer (item i of layerIndexList)
				copy thePosition to end of positionList
			end repeat
			
			-- Swap the positions.
			copy {item 2 of positionList, item 1 of positionList} to positionList
		else
			set theError to "Check if 2 layers is selected."
			error theError number -128
		end if
		
		-- Set the position of item i with the swap value. 
		repeat with i from 1 to 2
			tell front document to set position of layer (item i of layerIndexList) to (item i of positionList)
		end repeat
	end tell
end swapLayerWithPosition

-------------

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

Yes, I and I have written an Automator Service based on your suggestions which creates a watermark in my images.

Thanks!

Great, I thought for the moment I was the only one.

I have not get much responds on my posts in this forum.