Adobe Photoshop CS3
JavaScript Scripting Reference
JavaScript Object Reference 51
app.backgroundColor.rgb.red = Math.random() * 255
app.backgroundColor.rgb.green = Math.random() * 255
app.backgroundColor.rgb.blue = Math.random() * 255
}
// Open a document
if (app.documents.length == 0) {
// use the application’s path and the offset to the samples folder
var sampleDocToOpen = File(app.path + "/Samples/Fish.psd")
// compose a message with the name of the file
message = "Would you like me to open a sample for you? ("
m= sampleDocToOpen.fsName
m= ")"
// ask the user another question
answer = confirm(message)
// open the document accordingly
if (answer) {
open(sampleDocToOpen)
}
}
Second Sample Script
The following script presents a progression of images as an Adobe PDF slide show.
PDFPresentation.jsx
// use all the files in the Samples folder
var inputFolder = new Folder(app.path + "/Samples/")
// see if we have something interesting
if (inputFolder != null) {
// get all the files found in this folder that are Adobe Photoshop CS3 (.psd
format)
var inputFiles = inputFolder.getFiles("*.psd")
// output to the desktop
var outputFile = File("~/Desktop/JavaScriptPresentation.pdf")
// there are defaults but I like to set the options myself
var options = new PresentationOptions
options.presentation = true
options.view = true
options.autoAdvance = true
options.interval = 5
options.loop = true
options.transition = TransitionType.RANDOM
// create the presentation
makePDFPresentation(inputFiles, outputFile, options)
alert("Presentation file saved to: " + outputFile.fsName)
}