Moving contents of Photoshop CS layer

Ok, so this is my first script that I am trying to do within Photoshop… I am trying to avoid using Photoshop actions for a host of reasons.

So, I have a 5x7, 300 dpi image.

What I am trying to do is copy the contents, set the canvas size to 10x8, paste the clipboard into another layer, and position the contents of next to the original image.

I have the following:


tell application "Adobe Photoshop CS"
	activate
	set foreground color to {class:RGB color, red:255, green:255, blue:255}
	set background color to {class:RGB color, red:255, green:255, blue:255}
	tell current document
		select all
		copy
		resize canvas anchor position top left width (10) height (8)
		paste
		set current layer to layer "Layer 1"
		select contents
		move selection to {5, 0}
	end tell
end tell

The script errors out on the selection process of the contents of “Layer 1.” Can someone point me in the right direction.

I found the paste clipping to selection command - so, this is what I have done…


tell application "Adobe Photoshop CS"
	activate
	set foreground color to {class:RGB color, red:255, green:255, blue:255}
	set background color to {class:RGB color, red:255, green:255, blue:255}
	tell current document
		select all
		copy
		resize canvas anchor position top left width (10) height (8)
		set MySelect1 to select region {{1501, 0}, {3000, 0}, {3000, 2100}, {1501, 2100}}
		paste with clipping to selection
		
	end tell
end tell

Scott, not sure what you are doing here could you explain a bit further.

tell application "Adobe Photoshop CS"
	activate
	set background color to {class:RGB color, red:255, green:255, blue:255}
	tell current document
		set background layer of layer 1 to false
		resize canvas anchor position top left width (10) height (8)
	end tell
end tell

This part of the script simply changes the canvas size from 5x7 inches to 10x8 inches.

The rest of the script then duplicates the original 5x7 and positions it next to the original 5x7 on the 10x8 sheet.

Scott, its better to use duplicate within or detween documents rather than select all a copy, this can lead to some large files in the clip-board. For photoshop I also prefer to use pixel units. Pasting into an active selection will also create a layer mask which you may not require. Your selection array leaves a 1 pixel gap did you want this?

tell application "Adobe Photoshop CS"
	activate
	set ruler units of settings to pixel units
	set background color to {class:RGB color, red:255, green:255, blue:255}
	tell current document
		duplicate layer 1
		resize canvas anchor position top left width 3000 height 2400
		set current layer to layer 1
		translate layer 1 delta x pixels 1500
	end tell
end tell

Thanks for the tip!

I was leaving a one pixel gap between images (sacrificing one pixel on the far right side) but that is easy enough to factor in.

Is there a way to clear the clip-board prior to moving to another application, other than copying a single pixel to it?

resurrecting an old topic here… but, I never did get an answer to my last question.

Is there a way to clear the clip-board prior to moving to another application, other than copying a single pixel to it?

Hi

set the clipboard to ""

you may need to point this to the finder.

As in the regular interface you can use the purge command:

purge all caches/clipboard cache/history caches/undo caches : what to purge

Jerome,

What do you mean by “as in the regular interface”?

Photoshop’s edit menue has a purge command for the same caches as the script command, so if you have a large history or item in the clip board you can purge it to clear it from memory.

OMG!!! :o

How have I never freaking noticed that?!?!?

Thanks, Jerome!