
Photoshop CS Scripting Guide
66
Scripting Photoshop
The Application object
3
Opening a document
When using the open command there are a number of specifiable options. These options are
grouped by file type in the provided open options classes. Because the type and contents of the
file you are working on affects how it is opened, some of the option values may not always be
applicable. It also means that many of the option values do not have well defined default
values.
The best way to determine what values can or should be used for open is to perform an open
command from the user interface. You can then copy the value from the options dialog to your
script. You should perform a complete open
operation because there can be multiple dialogs
presented before the document is actually opened. If you cancel one of the open dialogs
without completing the operation you could miss seeing a dialog which contains values
needed in your script.
Specifying file formats to open
Because Photoshop supports many different file formats, the
Open
command lets you specify
the format of the document you are opening. If you do not specify the format, Photoshop will
infer the type of file for you. Here’s how to open a document using its default type:
AS:
set theFile to alias "MyFile.psd"
open theFile
VB:
fileName = "C:\MyFile.psd"
Set docRef = appRef.Open(fileName)
JS:
var fileRef = new File("//MyFile.psd");
var docRef = app.open (fileRef);
Notice that in JavaScript, you must create a
File
object, and it gets passed into the open
command. See the JavaScript file documentation for more information.
Some formats require extra information when opening. When you open a Generic EPS,
Generic PDF, Photo CD or Raw image you have to provide additional information to the open
command.
Do this by using the various
open options
classes:
• EPS Open Options (EPSOpenOptions/EPSOpenOptions)
• PDF Open Options (PDFOpenOptions/PDFOpenOptions)
• Photo CD Open Options (PhotoCDOpenOptions/PhotoCDOpenOptions)
• raw format Options (RawFormatOpenOptions/RawFormatOpenOptions)