// Jim Elder, Ottawa, Canada // see script reference guide in Program Files/Adobe... // Save the current preferences var startDisplayDialogs = app.displayDialogs; // Set Adobe Photoshop CS2 to use pixels and display no dialogs app.displayDialogs = DialogModes.NO; // ask the user for the input folder alert ("Edit the script to set your input and output directories, then delete this"); var inputFolder = new Folder("~/Videos/TimeLapse/psScripts"); var outputFolder = new Folder("~/Videos/TimeLapse/psScripts/output"); if (false) { // there is some problem with these -- the first one seems to execute twice -- so // it's been hard-code above inputFolder = new Folder.selectDialog("What folder contains the input images and clock.psd?"); outputFolder = new Folder.selectDialog("To what folder do you want the output written?") } // see if we got something interesting from the dialog if (inputFolder == null && outputFolder != null) alert ("Can't run without input and output folders") else { var clockRef = open(new File(inputFolder.path & "\clock.psd")); // get all the JPG files found in this folder var fileList = inputFolder.getFiles("*.jpg"); // save the outputs in JPEG var jpegOptions = new JPEGSaveOptions(); jpegOptions.quality = 10; // open each one in turn var startTime = 0; 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 && (fileList[i].name.toLowerCase().indexOf(".jpg") > 0)) { // get a reference to the new document var docRef = open(fileList[i]); var exif = docRef.info.exif; var dateEntry = exif[6]; var ds = dateEntry[1]; // 2008:01:28 14:02:11 0 5 8 11 14 17 var createDate = new Date(parseInt(ds.substring(0,4)), parseInt(ds.substring(5,7)) -1, parseInt(ds.substring(8,10)), parseInt(ds.substring(11,13)), parseInt(ds.substring(14,17)), parseInt(ds.substring(17,19))); if (startTime == 0) startTime = createDate.getTime(); var offsetSeconds = (createDate.getTime() - startTime) / 1000; app.activeDocument = clockRef; // Set hour hand var hourHand = clockRef.layers.getByName("hourHand"); clockRef.activeLayer = hourHand; clockRef.activeLayer = clockRef.activeLayer.duplicate(); clockRef.selection.selectAll(); clockRef.selection.rotate((offsetSeconds / 120) % 360); // Set minute hand var minuteHand = clockRef.layers.getByName("minuteHand"); clockRef.activeLayer = minuteHand; clockRef.activeLayer = clockRef.activeLayer.duplicate(); clockRef.selection.selectAll(); clockRef.selection.rotate((offsetSeconds % 3600) / 10); // Copy clock to clipboard minuteHand.visible = false; hourHand.visible = false; clockRef.selection.selectAll(); clockRef.selection.copy(true); // Clean up clock clockRef.layers.getByName("minuteHand copy").remove(); clockRef.layers.getByName("hourHand copy").remove(); // Paste clock to target doc app.activeDocument = docRef; docRef.paste(); docRef.activeLayer.translate((docRef.width - clockRef.width - 25) - docRef.activeLayer.bounds[0], (docRef.height - clockRef.height - 25) - docRef.activeLayer.bounds[1]); docRef.flatten(); // save and close docRef.saveAs(new File(outputFolder + "/" + fileList[i].name), jpegOptions) // do not modify the original docRef.close(SaveOptions.DONOTSAVECHANGES) } } } clockRef.close(SaveOptions.DONOTSAVECHANGES); // Reset the application preferences app.displayDialogs = startDisplayDialogs;