Sunday, May 9, 2021

#1 2021-04-19 05:17:42 am

CrownOnTheRocks
Member
Registered: 2006-09-15
Posts: 3

Append Selection in Photoshop with AppleScript

I need a way to add (append) to a selection in Photoshop using AppleScript.

In order to paste a pathed image from one image onto a template image in exactly the correct position, I need to add a small square of selection in the upper left corner of the image after loading the path as a selection. I will remove these pixels later. The result will need to be a perfectly sized/placed transparent .png image for a website.

To create a selection of the path and then append to the selection a small area in the upper left corner.

I thought about creating a new path on the template but how do I load BOTH paths as a selection.
in Photoshop I just use the shift key. Then I thought maybe/how to use System Events to use the shift key for this task...

Can anyone give some ideas on how I can do this? I have tried all day yesterday!

(Another option for me would be an ability to paste a selected area and move it on the layer to be centered and on a baseline)


tell application "Adobe Photoshop 2021"
    activate
    tell current document
        create selection path item "Path 1"
        (select region {{0, 0}, {50, 0}, {50, 50}, {0, 50}})
    end tell
end tell

Thank you for any suggestions!

Model: 2019 MacBook Pro 16"
AppleScript: Script Debugger 7
Browser: Safari 605.1.15
Operating System: macOS 10.14

Offline

 

#2 2021-04-19 08:51:16 am

CrownOnTheRocks
Member
Registered: 2006-09-15
Posts: 3

Re: Append Selection in Photoshop with AppleScript

As a solution, I am trying to combine 2 paths into one selection. I think this is possible? Below errors.
path named "GUIDE_01" already exists. If I can make a selection of both paths I can move on!

tell application "Adobe Photoshop 2021"
    activate
    tell current document
        (select region {{0, 0}, {50, 0}, {50, 50}, {0, 50}})
        make work path selection tolerance 1
        set properties of path item "Work Path" to {name:"My path"}
        make clipping path path item "My path" flatness 1
       
        --set theClippingPaths to {path item "My path", "GUIDE_01"} --ALSO ERRORS
        create selection {path item "My path" & path item "GUIDE_01"} feather amount 0 with antialiasing
       
        return

Offline

 

#3 2021-04-19 04:59:25 pm

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 1017

Re: Append Selection in Photoshop with AppleScript

Hi. I don't believe this can be done using a region, as you'd end up with a shape that intersects itself. If you have two paths:

Applescript:


tell application "Adobe Photoshop CS3"'s document 1
   create selection path item 1 operation replaced
   create selection path item 2 operation extended
end tell

Offline

 

#4 2021-04-19 08:23:11 pm

CrownOnTheRocks
Member
Registered: 2006-09-15
Posts: 3

Re: Append Selection in Photoshop with AppleScript

Hi Marc

YES!!!!
THANK YOU SO MUCH.

I gave it my best for about a day. I could not find a solution anywhere.
This does exactly what I need. Now when I copy and paste onto a template image that has a selection active, it places the image in the perfect position.  Apples to Apples now. Original image has a canvas size created exactly the size of the selection in the final template.

I only had to add deselect the path. I'll write something to remove the square of white pixels on my final template.

Thank you again Marc. I am grateful.


tell application "Adobe Photoshop 2021"
    activate
    tell current document
        (select region {{0, 0}, {50, 0}, {50, 50}, {0, 50}})
        make work path selection tolerance 1
        set properties of path item "Work Path" to {name:"My path"}
        make clipping path path item "My path" flatness 1

        create selection path item "My path" operation replaced
        create selection path item "Path 1" operation extended
        deselect path item "My path"
       
        return

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)