[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