C
HAPTER
3: Scripting Photoshop
Understanding Clipboard Interaction
55
N
OTE
:
If your script creates a new document in which you paste the clipboard contents, be sure the
document uses the same ruler units as the original document. See
“Setting Application Preferences” on
page 32
for information.
AS
N
OTE
:
On Mac OS, Photoshop must be the front-most application when executing these commands. You
must use the
activate
command to activate the application before executing any clipboard commands.
tell application "Adobe Photoshop CS5"
activate
select all of current document
copy
set current layer of current document to layer "Background" ¬
of current document
set newDocRef to make new document
paste newDocRef
end tell
VBS
'make firstDocument the active document
Set docRef = appRef.ActiveDocument
docRef.ArtLayers("Background").Copy
Set newDocRef = appRef.Documents.Add(8, 6, 72, "New Doc")
newDocRef.Paste
JS
//make firstDocument the active document
var docRef = app.activeDocument
docRef.artLayers["Background"].copy()
var newDocRef = app.documents.add(8, 6, 72, "New Doc")
newDocRef.paste()
Using the copy merged command/method
You can also perform a merged copy to copy all visible layers in the selected area. In AppleScript, you use
the
copy
merged
command. For VBScript and JavaScript, you use the
Copy/copy
command, passing in a
value of
True/true
for the optional
merge
parameter.
AS
N
OTE
:
On Mac OS, Photoshop must be the front-most application when executing these commands. You
must use the
activate
command to activate the application before executing any clipboard commands.
set docRef to make new document
make new art layer of docRef
select all of docRef
copy merged selection of docRef
VBS
docRef.Selection.Copy True
Look up the
Copy
method for the
ArtLayer
and
Selection
objects in the
Adobe Photoshop CS5 Visual
Basic Scripting Reference
, or in the Visual Basic Object Browser
JS
docRef.selection.copy(true)
Look up the
copy()
method for the
ArtLayer
and
Selection
objects in the
Adobe Photoshop CS5
JavaScript Scripting Reference
, or in the ExtendScript Object Model Viewer.