Tim Joe
Tim Joe

Reputation: 475

Photoshop Applescript looking for Java Injection

So I have an applescript move the current layer (part a bigger script that find how far to move):

set MoveTicks to {5,5}
tell application id "com.adobe.Photoshop"
    tell current document
        translate layer 1 delta x (item 1 of MoveTicks) as pixels
        translate layer 1 delta y (item 2 of MoveTicks) as pixels
    end tell
end tell

My issues is that "Translate" is relative to the current position. I kind want to input the destination points. It also seems a little weird trying to get an exact position if I translate a few times and it get a decimal place X/Y cord.

I don't know javascript but in the past I have found it can do things applescript can't. Can one help me or point in the direction of a piece of Javascript that will move use inputs of {LayerName, X_Cord, Y_Cord} X,Y would preferably be the top left anchor point.

Upvotes: 0

Views: 113

Answers (1)

ShooTerKo
ShooTerKo

Reputation: 2282

You can do it with Applescript. The trick is to move the layer to the origin in a first step. After that you can move your layer relative to the origin what makes the two relative moves to an absolute move. Maybe the script makes it clearer:

set MoveTicks to {5, 5}
tell application id "com.adobe.Photoshop"
    tell current document
        tell layer 1
            -- getting the bounds of the layer
            set {layX1, layY1, layX2, layY2} to bounds
            -- move the layer to origin
            translate delta x -layX1 delta y -layY1
            -- move the layer to the target coordinates
            translate delta x (item 1 of MoveTicks) as pixels
            translate delta y (item 2 of MoveTicks) as pixels
        end tell
    end tell
end tell

Greetings, Michael / Hamburg

Upvotes: 0

Related Questions