Skip to main content
brifilone
Participating Frequently
April 25, 2011
Answered

Moving a layer in Photoshop CS5 using Applescript

  • April 25, 2011
  • 1 reply
  • 5284 views

I have a layer in a document called "logo" and i want to duplicate it to every open document and then move it to a specific spot in each document

I got the duplicating thing happening but cant seem to move the bounds of the layer (says it is read only and cannot be changed)

here is what I have written

tell application "Adobe Photoshop CS5"

activate

set theDocs to count of documents

repeat with i from 1 to theDocs

duplicate art layer "logo" of current document to document i

end repeat

repeat with i from 1 to theDocs

set current document to document i

tell document i

set bounds of art layer "logo" to {0.456666666667, 6.38, 2.88, 6.77}

--Adobe Photoshop CS5 got an error: Property is read/only and cannot be changed

end tell

end repeat

end tell

This doesn't error but also doesn't move the logo at all

tell application "Adobe Photoshop CS5"

activate

set theDocs to count of documents

repeat with i from 1 to theDocs

duplicate art layer "logo" of current document to document i

end repeat

repeat with i from 1 to theDocs

set current document to document i

tell document i

set properties of art layer "logo" to {bounds:{0.456666666667, 6.38, 2.88, 6.77}}

end tell

end repeat

end tell


anyone know what the language is to move the layer around?

This topic has been closed for replies.
Correct answer Muppet_Mark-QAl63s

In any language the way to move a layer x,y is to use translate… You will need to do the math from current x,y to required x,y given a distance… A read only property is just that regardless of language… Here is a quick example of how I did this kind of thing using Applescript… I still do the same method now but use the ESTK instead…

tell application "Adobe Photoshop CS2"

activate

-- Store the app settings

set User_Rulers to ruler units of settings

set User_Dialogs to display dialogs

set ruler units of settings to pixel units

set display dialogs to never

set Doc_Ref to the current document

tell Doc_Ref

-- Store the image res so we can put it back

set Original_Res to resolution

-- Change to work at 72 dpi

resize image resolution 72 resample method none

-- Move horizontal 1 inch

translate layer 1 delta x 72 as pixels

-- Move vertical 1 inch

translate layer 1 delta y 72 as pixels

-- Read the bounds propety

set Layer_Bounds to bounds of layer 1

log Layer_Bounds

-- Move the layer using bounds to top/left

translate layer 1 delta x -(item 1 of Layer_Bounds) as pixels

translate layer 1 delta y -(item 2 of Layer_Bounds) as pixels

-- Put back the image res

resize image resolution Original_Res resample method none

end tell

-- Put back the app settings

set ruler units of settings to User_Rulers

set display dialogs to User_Dialogs

end tell

You should get the general idea of how this works from this. It should move the first layer across 1 inch, down i inch then put it top/left. It assumes you have a layer that is not a background layer nor is it locked in any way…

1 reply

Muppet_Mark-QAl63s
Muppet_Mark-QAl63sCorrect answer
Inspiring
April 25, 2011

In any language the way to move a layer x,y is to use translate… You will need to do the math from current x,y to required x,y given a distance… A read only property is just that regardless of language… Here is a quick example of how I did this kind of thing using Applescript… I still do the same method now but use the ESTK instead…

tell application "Adobe Photoshop CS2"

activate

-- Store the app settings

set User_Rulers to ruler units of settings

set User_Dialogs to display dialogs

set ruler units of settings to pixel units

set display dialogs to never

set Doc_Ref to the current document

tell Doc_Ref

-- Store the image res so we can put it back

set Original_Res to resolution

-- Change to work at 72 dpi

resize image resolution 72 resample method none

-- Move horizontal 1 inch

translate layer 1 delta x 72 as pixels

-- Move vertical 1 inch

translate layer 1 delta y 72 as pixels

-- Read the bounds propety

set Layer_Bounds to bounds of layer 1

log Layer_Bounds

-- Move the layer using bounds to top/left

translate layer 1 delta x -(item 1 of Layer_Bounds) as pixels

translate layer 1 delta y -(item 2 of Layer_Bounds) as pixels

-- Put back the image res

resize image resolution Original_Res resample method none

end tell

-- Put back the app settings

set ruler units of settings to User_Rulers

set display dialogs to User_Dialogs

end tell

You should get the general idea of how this works from this. It should move the first layer across 1 inch, down i inch then put it top/left. It assumes you have a layer that is not a background layer nor is it locked in any way…

brifilone
brifiloneAuthor
Participating Frequently
April 26, 2011

Thanks I couldn't get that translate language right before now I see how it's used.