The sample scripts in this section activate a Adobe Photoshop CS2 Application object and then save the default configuration settings into variables so that they can be restored later when the script completes. These are the default configurations you most probably set up in the Preferences dialog when you initially installed and configured Adobe Photoshop CS2.
Note: To view or set the Preferences on Mac OS, choose Photoshop >Preferences> Units & Rulers; in Windows choose Edit >Preferences> Units & Rulers.
To work with document preferences:
- Create the following script.
//create and assign variables for default preferences startRulerUnits = app.preferences.rulerUnits startTypeUnits = app.preferences.typeUnits startDisplayDialogs = app.displayDialogs //change settings app.preferences.rulerUnits = Units.INCHES app.preferences.typeUnits = TypeUnits.PIXELS app.displayDialogs = DialogModes.NO //create and assign variables for document settings docWidthInInches = 4 docHeightInInches = 2 resolution = 72 //use the length property of the documents object to //find out if any documents are open //if none are found, add a document if (app.documents.length == 0) app.documents.add(docWidthInInches, docHeightInInches, resolution) //restore beginning preferences app.preferences.rulerunits = startRulerUnits app.preferences.typeunits = startTypeUnits app.displayDialogs = startDisplayDialogs
- Name the script HelloWorldDoc.jsx and save it in the Scripts folder.
- Open Adobe Photoshop CS2 and choose File > Scripts > HelloWorldDoc to run the script.
- Choose Edit > Preferences > Units & Rulers to verify that your preferences have been returned to your original settings.
- After viewing the document in Adobe Photoshop CS2, close the document without saving it.
- To prepare the script for the next section, comment the statements that restore the beginning preferences by adding slashes as follows:
//app.preferences.rulerunits = startRulerUnits //app.preferences.typeunits = startTypeUnits
- Save the script.