Adobe Photoshop

Scripts can also be used to modify metadata. The Photoshop document object model (DOM) is a containment hierarchy, at the top of which is situated the Application object. Within this hierarchy are channels, layers, paths and other components that make up the document. Metadata resides within the Document Info class (within the application menus the term "file info" is used).

The following script sets the author, caption and copyrighted status of a document:

var docRef = open(fileList[i])
// set the file info
docRef.info.author = "Andrew Armour"
docRef.info.caption = "Peacock and Shelley"
docRef.info.copyrighted = CopyrightedType.PUBLICDOMAIN

Note that the CopyrightedType can take one of 3 values: COPYRIGHTEDWORK, PUBLICDOMAIN, or UNMARKED.

For the purposes of the ADIEUX Project, it is useful to employ a script to generate low-quality images from the high-resolution source files to use for display on a website and/or as vessels for steganography. The metadata can be incorporated simultaneously:

// Save the current preferences
var startDisplayDialogs = app.displayDialogs
// Set Adobe Photoshop CS4 to use pixels and display no dialogs
app.displayDialogs = DialogModes.NO
// ask the user for the input and output folders
var inputFolder = Folder.selectDialog("Select a folder to tag")
var outputFolder = Folder.selectDialog("Select a folder for the output files")
// see if we got something interesting from the dialog
if (inputFolder != null && outputFolder != null) {
// get all the files found in this folder
var fileList = inputFolder.getFiles()
// save the outputs in JPEG
var jpegOptions = new JPEGSaveOptions()
// set the jpeg quality low so the files are small
jpegOptions.quality = 5
// open each one in turn
for (var i = 0; i < fileList.length; i++) {
// The fileList includes both folders and files so open only files
if (fileList[i] instanceof File && fileList[i].hidden == false) {
// get a reference to the new document
var docRef = open(fileList[i])
// tag all of the documents with photo shoot information
docRef.info.author = "Andrew Armour"
docRef.info.caption = "Thomas Love Peacock"
docRef.info.captionWriter = "Andrew Armour"
docRef.info.city = "Tokyo"
docRef.info.copyrightNotice = "Copyright (c) ADIEUX Project"
docRef.info.copyrighted = CopyrightedType.COPYRIGHTEDWORK
docRef.info.country = "Japan"
// change the date to a Adobe Photoshop CS4 date format
// "YYYYMMDD"
var theDate = new Date()
// the year is from 1900 ????
var theYear = (theDate.getYear() + 1900).toString()
// convert the month from 0..12 to 00..12
var theMonth = theDate.getMonth().toString()
if (theDate.getMonth() < 10) {
theMonth = "0" + theMonth
}
// convert the day from 0..31 to 00.31
var theDay = theDate.getDate().toString()
if (theDate.getDate() < 10) {
theDay = "0" + theDay
}
// stick them all together
docRef.info.creationDate = theYear + theMonth + theDay
// flatten because we are saving to JPEG
docRef.flatten()
// go to 8 bit because we are saving to JPEG
docRef.bitsPerChannel = BitsPerChannelType.EIGHT
// save and close
docRef.saveAs(new File(outputFolder + "/Output" + i + ".jpg"), jpegOptions)
// don’t modify the original
docRef.close(SaveOptions.DONOTSAVECHANGES)
}
}
}
// Reset the application preferences
app.displayDialogs = startDisplayDialogs

This script is based on one provided in a scripting guide by Adobe: Photoshop CS4 JavaScript Ref.pdf.

Continued Continued