Batch export layers individually ?
2020-12-11 12:21:30
I export a lot of layers, and it takes a lot of time to check and uncheck e.g. 20 layers and save them with a numerically incremented name e.g. "layer1", "layer2" (and not necessarily the name of the layer itself).
Is there a feature in the Pro version that allows batch export of layers, which can be renamed before exporting, or at least the ability to batch export each layer individually ?
Is there a feature in the Pro version that allows batch export of layers, which can be renamed before exporting, or at least the ability to batch export each layer individually ?
0
2021-01-04 16:55:35
Many thanks for the reply.
I do not have Pro, unfortunately I don't see a need to upgrade with the Pixelart style that I employ.
However, quality of life features like that would be universally welcome, as well as batch renaming layers and files in layers.
There are a number of GitHub repositories that handle batch renaming, as you list that some of your extensions are natively written in Swift the closest I found was a C++ cross-platform effort by Guid75 called "renamah" which is apparently "modular", which would make it easier to implement:
https://github.com/Guid75/renamah
I do not have Pro, unfortunately I don't see a need to upgrade with the Pixelart style that I employ.
However, quality of life features like that would be universally welcome, as well as batch renaming layers and files in layers.
There are a number of GitHub repositories that handle batch renaming, as you list that some of your extensions are natively written in Swift the closest I found was a C++ cross-platform effort by Guid75 called "renamah" which is apparently "modular", which would make it easier to implement:
https://github.com/Guid75/renamah
0
2021-01-05 11:13:19
That's totally your call. But if you haven't actually tried the app, you should definitely at least check out the free trial.
If we did decide to create a feature like this, I reckon the code part wouldn't be the problem. But thanks for the suggestion, either way!There are a number of GitHub repositories that handle batch renaming, as you list that some of your extensions are natively written in Swift the closest I found was a C++ cross-platform effort by Guid75 called "renamah" which is apparently "modular", which would make it easier to implement:
https://github.com/Guid75/renamah
0
2021-09-15 17:18:42
Hi @andrius,
I am dealing with the same request:
- 50 headshots all nicely cropped and fitted into one file
- rather not hide/unhide/export one by one but have a batch export
Dragging to e.g. the desktop is great, but the sizing is based on the original, not the Canvas Size.
If you can write an Apple Script, I would much appreciate that offer!
Have a great day
Roland
I am dealing with the same request:
- 50 headshots all nicely cropped and fitted into one file
- rather not hide/unhide/export one by one but have a batch export
Dragging to e.g. the desktop is great, but the sizing is based on the original, not the Canvas Size.
If you can write an Apple Script, I would much appreciate that offer!
Have a great day
Roland
0
2021-09-15 18:08:12
Hi Roland! I've posted a script for a similar workflow in this thread here. Perhaps you'll find some use for it. I don't think you'd need much overwriting either — just remove the 50% resizing and the @0.5x.jpg extension, I guess? And, of course, choose the export file format you want. Essentially, a very basic export script would look something like this:
tell application "Pixelmator Pro"
set exportLocation to choose folder with prompt "Please choose where you'd like to export the images:"
tell the front document
set visible of every layer to false
set visible of the last layer to true
repeat with currentLayer in every layer
set visible of currentLayer to true
export for web to ((exportLocation as text) & name of currentLayer & ".jpg") as JPEG with properties {compression factor:100}
set visible of currentLayer to false
end repeat
end tell
end tell
0
2021-09-16 16:45:28

Not much of an Automator expert... could you tell me where to start or maybe even send me the file to run it?
UPDATE: this seems to work like a charm for some files with e.g. 3 pictures, but when I have a file with 5, I only get one exported picture. No clue what is causing one file to export all three when I have three layers and only one when I have five images in another layered file. I send these PXM files via email.
Thanks,
Roland
0
2021-09-17 07:42:47
You'd typically run AppleScipts using the Script Editor (just copy and paste the script into a new document and run it), but you can alternatively use Automator's 'Run AppleScript' action if you so prefer, which I can see you did.
Thanks for sending in the documents, by the way. The issue I found is that one of them features layers that all share the same name. Since you're exporting all these layers to the same folder — that causes conflict on macOS. You can't have two files with the same title in the same folder. In other words, one file overwrites the other. My quick suggestion would be to rename the layers so that they all have unique names. Any other ideas on how to potentially do this layer renaming in-script are welcome though — I'm not very pro at scripting yet.
Thanks for sending in the documents, by the way. The issue I found is that one of them features layers that all share the same name. Since you're exporting all these layers to the same folder — that causes conflict on macOS. You can't have two files with the same title in the same folder. In other words, one file overwrites the other. My quick suggestion would be to rename the layers so that they all have unique names. Any other ideas on how to potentially do this layer renaming in-script are welcome though — I'm not very pro at scripting yet.
1
2021-09-17 09:39:10
I got a little carried away, bur, errr, here's one solution...
tell application "Pixelmator Pro"
set exportLocation to choose folder with prompt "Please choose where you'd like to export the images:"
tell the front document
set visible of every layer to false
set visible of the last layer to true
repeat with currentLayer in every layer
set visible of currentLayer to true
set fileName to name of currentLayer
set fileExtension to ".jpg"
if my fileExistsAt((exportLocation as text) & fileName & fileExtension) then
set fileName to my overwriteOriginalFile(fileName, fileExtension)
end if
export for web to (exportLocation as text) & fileName & fileExtension as JPEG with properties {compression factor:100}
set visible of currentLayer to false
end repeat
set visible of every layer to true
end tell
end tell
on fileExistsAt(filePath)
tell application "Finder"
if exists file filePath then
return true
end if
end tell
return false
end fileExistsAt
on overwriteOriginalFile(fileName, fileExtension)
tell application "Pixelmator Pro"
set overwriteOriginal to display dialog "A file named \"" & fileName & fileExtension & "\" already exists at your export location. Would you like to overwrite it or choose a new name?" buttons {"Cancel", "Overwrite", "Rename"} with icon note default button "Rename" cancel button "Cancel"
if button returned of overwriteOriginal is "Overwrite" then
return fileName
else
set newFilename to display dialog "New filename:" default answer "" with icon note buttons {"Cancel", "Continue"} default button "Continue"
return text returned of newFilename
end if
end tell
end overwriteOriginalFile
A simpler method would look like this:tell application "Pixelmator Pro"
set exportLocation to choose folder with prompt "Please choose where you'd like to export the images:"
tell the front document
set visible of every layer to false
set visible of the last layer to true
set a to 1
set fileExtension to ".jpg"
repeat with currentLayer in every layer
set visible of currentLayer to true
set fileName to name of currentLayer
export for web to (exportLocation as text) & fileName & a & fileExtension as JPEG with properties {compression factor:100}
set visible of currentLayer to false
set a to a + 1
end repeat
set visible of every layer to true
end tell
end tell
Of course, it's also possible to write a script that would do the usual macOS thing of adding the next available number to the filename, but I think I've already spent a little too much time on this and I'm not sure that's exactly what you need.
2
2021-09-17 15:15:32
Thanks! I will look into using your method. Very dumb of me to not realize I was using similar names.2021-09-17 14:42:47 You'd typically run AppleScipts using the Script Editor (just copy and paste the script into a new document and run it), but you can alternatively use Automator's 'Run AppleScript' action if you so prefer, which I can see you did.
Thanks for sending in the documents, by the way. The issue I found is that one of them features layers that all share the same name. Since you're exporting all these layers to the same folder — that causes conflict on macOS. You can't have two files with the same title in the same folder. In other words, one file overwrites the other. My quick suggestion would be to rename the layers so that they all have unique names. Any other ideas on how to potentially do this layer renaming in-script are welcome though — I'm not very pro at scripting yet.
0
2021-09-17 15:16:41
That’ll keep me busy!2021-09-17 16:39:10 I got a little carried away, bur, errr, here's one solution...
A simpler method would look like this:
Of course, it's also possible to write a script that would do the usual macOS thing of adding the next available number to the filename, but I think I've already spent a little too much time on this and I'm not sure that's exactly what you need.
Would something like this be achievable with the new Shortcuts functionality on the next release?
0
2021-09-20 10:17:32
2021-10-31 23:40:12
I used your Apple Script and dragged it into the Shortcuts App... works great... just doesn't look as clean. ;o)
0
2021-11-02 10:03:40
I don't think I've seen enough shortcuts to make this worthwhile just yet but it's definitely something to consider!
And it's really great to hear you've become obsessed with shortcuts. I love them too!
0
2022-02-02 13:14:26
Hello,
I'm struggling with Applescript to do something very, very, simple but I can't write the right code. I've tried many solutions, using the Pixelmator Pro dictionary, mobilizing what I understand and reusing bits of code from here and there, but it doesn't work.
Need: as a first step, I have ±200 svg files from which I need to export a specific layer, as a new file, in original png resolution, named with the same name as the svg.
To find the layer, 2 options are possible:
- either use the name of the last layer group (always called "map") which contains only one layer
- or the fact that it is the very last layer.
I tried with the "select" command:
I tried with the "layer" class:
and many other things (hide all layers and make the last layer visible but it doesn't work)
Here is my try:
Thanks in advance for your help.
sources :
I'm struggling with Applescript to do something very, very, simple but I can't write the right code. I've tried many solutions, using the Pixelmator Pro dictionary, mobilizing what I understand and reusing bits of code from here and there, but it doesn't work.
Need: as a first step, I have ±200 svg files from which I need to export a specific layer, as a new file, in original png resolution, named with the same name as the svg.
To find the layer, 2 options are possible:
- either use the name of the last layer group (always called "map") which contains only one layer
- or the fact that it is the very last layer.
I tried with the "select" command:
tell the frontend document to select (all layers whose name starts with "m")
.I tried with the "layer" class:
tell the front document to select the last layer
.and many other things (hide all layers and make the last layer visible but it doesn't work)
Here is my try:
tell application "Pixelmator Pro"
-- Open a prompt that lets you pick multiple Pixelmator Pro files to process
-- and save references to all those images in the originalImages variable
set originalImages to choose file with prompt ¬
"Please select the images to process:" with multiple selections allowed
-- Open a prompt that lets you define export destination
set exportLocation to choose folder with prompt "Please select where you'd like export the images:"
-- Start a repeat loop that loops over each image
repeat with a from 1 to number of originalImages
-- Open the current image in the loop
set currentImage to open item a of originalImages
tell currentImage to select (every layer whose name begins with "m")
tell the currentImage to select (every layer whose name begins with "m")
-- Export the selected layer (I am concsious that invoquing"layer" doesn't work)
export layer to file ((exportLocation as text) & name of currentImage & ".png") as JPEG with properties {compression factor:95}
close currentImage without saving
end repeat
display notification (number of originalImages as text) & " images exported to PNG." with title "Export Map to PNG"
end tell
Thanks in advance for your help.
sources :
0
2022-02-09 10:40:49
2022-02-02 11:14:26 Hello,
I'm struggling with Applescript to do something very, very, simple but I can't write the right code. I've tried many solutions, using the Pixelmator Pro dictionary, mobilizing what I understand and reusing bits of code from here and there, but it doesn't work.
Need: as a first step, I have ±200 svg files from which I need to export a specific layer, as a new file, in original png resolution, named with the same name as the svg.
To find the layer, 2 options are possible:
- either use the name of the last layer group (always called "map") which contains only one layer
- or the fact that it is the very last layer.I tried with the "select" command:
.
I tried with the "layer" class:
.
and many other things (hide all layers and make the last layer visible but it doesn't work)Here is my try:
Thanks in advance for your help.
sources :
Hey Cadel. Apologies for the late reply! After tweaking a few things (defining the currently selected layer as a variable), I think I managed to get the script working on my end:
tell application "Pixelmator Pro"
set originalImages to choose file with prompt ¬
"Please select the images to process:" with multiple selections allowed
set exportLocation to choose folder with prompt "Please select where you'd like export the images:"
repeat with a from 1 to number of originalImages
set currentImage to open item a of originalImages
select the last layer of the front document
set mapLayer to the current layer of the front document
export for web mapLayer to file ((exportLocation as text) & name of currentImage & ".png") as JPEG with properties {compression factor:95}
close currentImage without saving
end repeat
display notification (number of originalImages as text) & " images exported to PNG." with title "Export Map to PNG"
end tell
Let me know if it does for you!
0
2022-02-10 13:58:10
Hi Aurelija,
Thanks for your help.
It doesn't work for me
To be more visual here is the initial organisation of the layers:

And here is my goal (on which I add the super resolution before exporting to PNG and Motion format):

I know I'm asking a lot
So let's break it down and see what we can do.
Actually, I checked step by step this code and it seems that the script doesn't understand that I need the last nested layer. From what I could find in the forum, the script doesn't know how to go deep and stays at the first layer levels (I couldn't find Andrius' post about it), I don't know if it's clear.
Not waiting for your answer, I partially answered my need by using another way by using "ungroup" to flatten the nested layers and the nested group with this script:
tell application "Pixelmator Pro"
set originalImages to choose file with prompt ¬
"Please select the images to process:" with multiple selections allowed
set exportLocation to choose folder with prompt "Please select where you'd like export the images:"
repeat with a from 1 to number of originalImages
set currentImage to open item a of originalImages
ungroup currentImage's layers
ungroup currentImage's layers
super resolution currentImage
-- Need
-- ungroup currentImage's layers
-- hide layer group Flag
-- duplicate country text layer renamed by the Capital name (cf. end of this post)
-- create a group called "Capital", and add "oval" layer and [Capital name] layer, center this group at the middle of the image
-- create "Text" group handling country name layer and "Capital" subgroup
-- create group named after its file name, and organise the subgroup according the screenshot
export currentImage to ((exportLocation as text) & name of currentImage & ".png") as PNG with properties {compression factor:100}
export currentImage to ((exportLocation as text) & name of currentImage) as Motion
close currentImage with saving
end repeat
display notification (number of originalImages as text) & ¬
" images have been successfully processed." with title "Export Map Clean SVG and Motion"
end tell
This is what I get:

Ideally, I need to be able to :
- rename a layer or a group of layers -> is this possible? I haven't found anything in the dictionary nor forum
- hide a specific layer (founded by his name (here I need to hide "Flag" layer group) or its position 3rd subgroup)
- rearrange layers or layer group
One way to reach my goal would be to:
Ungroup once more and but I would lose the group that handles all the nested groups ... unless I ungroup and put all those groups into a new group (named after the file name) in a specific order.
I tried to use the following piece of code, but I could not rename "newGroup" ( using the file name).
set newGroup to make new group layer at the front of layers
move the last layer to the front of layers of newGroup
Here's an original file you can play with
https://www.dropbox.com/s/6kgw30c375pq7 ... a.svg?dl=0
Subsidiary question:
Is it possible to tell the script to search for the capital of the country in a spreadsheet according to the name of the file and to create a text layer (renamed to the name of the capital in question), with the text inserted in the middle of the image?
That would be crazy.
Whatever the answer, thank you for reading this far and thank you for any help
0