Adobe Photoshop CS2 – Working with document preferences

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:

  1. 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
    
  2. Name the script HelloWorldDoc.jsx and save it in the Scripts folder.
  3. Open Adobe Photoshop CS2 and choose File > Scripts > HelloWorldDoc to run the script.
  4. Choose Edit > Preferences > Units & Rulers to verify that your preferences have been returned to your original settings.
  5. After viewing the document in Adobe Photoshop CS2, close the document without saving it.
  6. 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
    
  7. Save the script.