Some of the interactions done with tools are not (easily) scriptable, for example brush strokes or pathpoint manipulation via pen tools.
In Photoshop Actions you can activate tool recording which works kind of but I assume in a scripting context you’d have to deal with raw data which apparently isn’t that easy handle. Also, I just tested to record adding 3 points with the pen tool and playing back the action made my Photoshop freeze 2 out of 2 times.
Luckily, the pen tools have a nice and readable underlying data structure (unlike brush tools): Paths.
So you can build your paths using that data model and directly set the working path to then make a shape of it. You can either use Alchemist to inspect the object structure or look at the types i’ve put together on github. Using the types makes working with Paths super easy since you get type safety, autocompletion etc.
Alternatively, you can also use the scriptable tools that produce Path objects (as you’re already doing), such as the rectangle tool and so on. You don’t have to create a layer for every path object though. If you replace the
set event with
addTo you can stack multiple rectangles in one path and then make one shape layer from it.
The good thing about paths is that 1) they’re made out of bezier curves so you can do all sorts of calculatiuons and manipulations on them (there are some great libraries for that) and 2) paths are “lightweight” and updated super quickly by Photoshop when you set them from a script.
Here’s an example of one of my plugins that builds and updates custom shapes, the update happens almost immediately: