[Tutorial] Advanced automation and scripting with AppleScript

Discuss Pixelmator Pro tutorials and share useful resources.
User avatar

2022-03-04 14:37:29

hello sorry evry time i used to run this code
tell application "Pixelmator Pro"
	display alert "Hello, world!"
end tell
in apple script i will have this error
Syntax Error
Internal table overflow.
what should i do
User avatar

2022-03-04 15:12:18

by hossein 2022-03-04 11:38:35 hello sorry evry time i used to run this code

in apple script i will have this error
Syntax Error
Internal table overflow.
what should i do
I think there was an issue in an older version of Pixelmator Pro with AppleScript generally, but everything should be working in the latest one – which version of Pixelmator Pro are you using? Also, which version of macOS are you on?
User avatar

2022-03-12 19:56:55

Remove horizontal slice of an image and fill its void by the surrounding areas from above and/or below

I inquired how to do this as a batch process at StackExchange and already got an answer how to do this with a Photoshop action. Would this be possible in Pixelmator with an AppleScript? If so, could you provide such a script or at least the rough directions?

Image
User avatar

2022-03-17 08:45:08

by abitofmind 2022-03-12 17:56:55 Remove horizontal slice of an image and fill its void by the surrounding areas from above and/or below

I inquired how to do this as a batch process at StackExchange and already got an answer how to do this with a Photoshop action. Would this be possible in Pixelmator with an AppleScript? If so, could you provide such a script or at least the rough directions?

<p><img src="https://i.stack.imgur.com/DUMqU.png" class="postimage is-shown is-visible" alt="Image" width="1160" height="540"></p>

Hey there! This script here should work for this crop:
tell application "Pixelmator Pro"
	activate
	tell the front document
		draw selection bounds {0, 140, 10000, 10000}
		cut
		paste
		deselect
		set position of the current layer to {0, 50}
		trim canvas mode transparency
		merge all
	end tell
end tell
You can further tweak the script to include or ask for a document save location, or create a Quick Action out of it — all depending on what you need for your workflow. Hope that helps!
User avatar

2022-03-18 16:21:52

@aurelija thanks for this! Reading the code already gives me an imagination of what will run in the GUI. Pretty intuitive how it's done! Thanks!
User avatar

2022-03-18 16:29:57

Setting a very high number of 10000 effectively achieves the selection to contain the remaining width/height in your script. Are there also variables like canvas.height, canvas.width, layer.height, layer.width, etc? (to include them in expressions/calculations)
User avatar

2022-03-22 11:22:13

by abitofmind 2022-03-18 14:29:57 Setting a very high number of 10000 effectively achieves the selection to contain the remaining width/height in your script. Are there also variables like canvas.height, canvas.width, layer.height, layer.width, etc? (to include them in expressions/calculations)
Ah, yes — if you'd like to define the exact boundaries of a layer in your selection, you can assign the layer width and layer height values like so:
tell application "Pixelmator Pro"
	activate
	tell the front document
		set layerWidth to width of the current layer
		set layerHeight to (height of the current layer) - 140
		draw selection bounds {0, 140, layerWidth, layerHeight}
		cut
		paste
		deselect
		set position of the current layer to {0, 50}
		trim canvas mode transparency
		merge all
	end tell
end tell
User avatar

2022-09-19 18:58:08

Can someone help me with changing the color of a newly inserted text layer. My first attempt is commented out below, and my second attempt was going to be via a gradient fill shape. I've got a start below, but now stuck on the coloring.
#
# Create a layer with text
#
set myColor to {10000, 12543, 23808}
set myColor1 to {10000, 12543, 23808}
set myColor2 to {14400, 7643,  9808}

tell application "Pixelmator Pro"
	activate
	tell the front document
		set myAlpha to {"Test1", "Test2"}
		repeat with myLetter in myAlpha
			
			set myText to make new text layer at the beginning of layers with properties ¬
				{text content:myLetter}
			tell the text content of myText
				--set its color to myColor # Can't get this to work?
				set its size to random number from 300 to 1000
				set its font to "Kai"
			end tell
                        set position of myText to {random number from 200 to 2800, random number from 100 to 1400}

                        convert into shape myText
                        --set its fill to gradient myColor1 to myColor2# Not sure this is possible? 
		end repeat
	end tell

end tell

Thanks - huge fan of Pixelmator pro, and just getting started with Apple Scripting.
User avatar

2022-09-20 08:42:17

Hi there, the fact that the color isn't changed looks to be a bug that probably appeared after the latest round of improvements to text layers. We'll do our best to fix it ASAP, but as a workaround, you can also change the color of text using layer styles:
tell the styles of myText
	set its fill color to {0, 0, 0}
end tell
Unfortunately, it isn't possible to use gradient fills, but that's something we can look into in the future!
User avatar

2022-09-20 16:50:36

Thanks for the workaround "fill color"! Glad to see this until the other bug is repaired.

Another question on the automation front. Is there any way to automate the create of new shape based on a custom design. I see the following in the tools, but no way to do it for a custom shape:
- rectangle shape layer
- rounded rectangle shape layer
- ellipse shape layer
- polygon shape layer
- star shape layer
- line shape layer

I would like to automate creation and placement of a custom shape
* myCustom shape layer

Thanks! Having fun learning to automate with applescript.
User avatar

Yesterday 03:48:00

Follow up question - is there any way to mirror a layer or object (flip horizontal/vertical) via Apple Script? But not the whole document (flip horizontally document)?