Script won't work on Windows

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

flygaff

Script won't work on Windows

Post by flygaff »

Hello all, first post here, and want to thank everyone for all of the help in advance. I have a script that I piled together, and it works fine on my mac, however when I use it on a windows computer, it won't work. Using CS4 on both...I have changed the script on the windows computer to reference a folder on that computer...This script asks for user input for filename, makes a copy, exports, closes copy, saves psd, closes psd...

Code: Select all// prompts for name, makes a copy, exports to 1000px @ 72,
#target photoshop
// define
var docRef = app.activeDocument;
// check and get back array of selected layers;
if (app.documents.length > 0) {
// get filename/folders
var fileName = prompt('Please enter base file name', docRef.name);
var basePath = '/Users/Tom/Desktop/Website Photos/NROImages/';
var basePath1 = '/Users/Tom/Desktop/Website Photos/PSDs/';
// set to pixels;
var originalRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
// define document;
var myDocument = app.activeDocument;
var theCopy = myDocument.duplicate ("copy", true);
// rgb;
theCopy.convertProfile ("sRGB IEC61966-2.1", Intent.RELATIVECOLORIMETRIC, true, true)
// resize;
if (theCopy.width > 1000) {
theCopy.resizeImage (1000, undefined, 72, ResampleMethod.BICUBIC)
}
else {
theCopy.resizeImage (undefined, undefined, 72, ResampleMethod.NONE)
};
// save for web options;
var exportOpts = new ExportOptionsSaveForWeb();
exportOpts.quality = 70;
exportOpts.format = SaveDocumentType.JPEG;
exportOpts.includeProfile = true;
// export;
theCopy.exportDocument (new File(basePath+fileName+".jpg"), ExportType.SAVEFORWEB, exportOpts);
// close document;
theCopy.close(SaveOptions.DONOTSAVECHANGES);
// reset;
preferences.rulerUnits = originalRulerUnits;
};
// save as psd
SavePSD(fileName);
function SavePSD(saveFile)
{
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true;
psdSaveOptions.layers = true;
activeDocument.saveAs(new File(basePath1+fileName+".psd"), psdSaveOptions, false, Extension.LOWERCASE);
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

Mike Hale

Script won't work on Windows

Post by Mike Hale »

Does it give you any error messages when you run it on Windows?

One thing I would change is the two variables that store paths to folders on the desktop. Instead of
Code: Select allvar basePath = '/Users/Tom/Desktop/Website Photos/NROImages/';
    var basePath1 = '/Users/Tom/Desktop/Website Photos/PSDs/';

I would use
Code: Select allvar basePath = '~/Desktop/Website Photos/NROImages/';
    var basePath1 = '~/Desktop/Website Photos/PSDs/';

The '~' is an ExtendScript shortcut to the user's folder and it cross-platform.

The only other thing I can think of is if those folders(NROImages and PSDs) do not already exists or the folder Website Photos itself does not exists the script will fail. You could add a check for those folders and have the script create them if they do not exists. Neither exportDocument() or save() will work if the path is not valid.
flygaff

Script won't work on Windows

Post by flygaff »

Mike, thanks for the help...That was the problem, I changed the format of the drive, and its working perfectly now!

Code: Select all// prompts for name, makes a copy, exports to 1000px @ 72,
#target photoshop
// check and get back array of selected layers;
if (app.documents.length > 0) {
// get filename/folders
var fileName = prompt('Enter the item number, without the .jpg extention', "Enter the item number, without the .jpg extention");
var basePath = '/y/TopLevel/jmtackle/Configuration/NROImages/';
var basePath1 = '/y/TopLevel/jmtackle/Configuration/PSDs/';
// set to pixels;
var originalRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
// define document;
var myDocument = app.activeDocument;
var theCopy = myDocument.duplicate ("copy", true);
// rgb;
theCopy.convertProfile ("sRGB IEC61966-2.1", Intent.RELATIVECOLORIMETRIC, true, true)
// resize;
if (theCopy.width > 1000) {
theCopy.resizeImage (1000, undefined, 72, ResampleMethod.BICUBIC)
}
else {
theCopy.resizeImage (undefined, undefined, 72, ResampleMethod.NONE)
};
// save for web options;
var exportOpts = new ExportOptionsSaveForWeb();
exportOpts.quality = 70;
exportOpts.format = SaveDocumentType.JPEG;
exportOpts.includeProfile = true;
// export;
theCopy.exportDocument (new File(basePath+fileName+".jpg"), ExportType.SAVEFORWEB, exportOpts);
// close document;
theCopy.close(SaveOptions.DONOTSAVECHANGES);
// reset;
preferences.rulerUnits = originalRulerUnits;
};
// save as psd
SavePSD(fileName);
function SavePSD(saveFile)
{
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true;
psdSaveOptions.layers = true;
activeDocument.saveAs(new File(basePath1+fileName+".psd"), psdSaveOptions, false, Extension.LOWERCASE);
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}