photoshop脚本 - 路径为变量

时间:2014-02-14 01:16:51

标签: javascript photoshop

这很好用,打开文件夹中的pdf

#target photoshop

app.bringToFront();
var path = 'C:/PhotoshopPortable/' 
// A hard coded path to a directory 'mac style'
var processFolder = Folder('C:/PhotoshopPortable/')
// Use folder object get files function with mask 'a reg ex'
var fileList = processFolder.getFiles(/\.(pdf)$/i);
// Loop through files

for (var i = 0; i < fileList.length; i++) {
     // Only process the returned file objects
     // The filter 'should' have missed out any folder objects 
     if (fileList[i] instanceof File && fileList[i].hidden == false) {
        // get a reference to the new document
        var docRef = open(fileList[i])
        // save and close
        saveJPEG(new File('C:/PhotoshopPortable/' + app.activeDocument.name + ".jpg"), 12)
        app.activeDocument.close();
     }
}

function saveJPEG(saveFile, jpegQuality){
    var doc = activeDocument;
    if (doc.bitsPerChannel != BitsPerChannelType.EIGHT) doc.bitsPerChannel = BitsPerChannelType.EIGHT;
    jpgSaveOptions = new JPEGSaveOptions();
    jpgSaveOptions.embedColorProfile = true;
    jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
    jpgSaveOptions.matte = MatteType.NONE;
    jpgSaveOptions.quality = jpegQuality; 
    activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);
}  

但这不会:

var path = 'C:/PhotoshopPortable/'
var processFolder = Folder(path)

它会打开一些带有(Mozilla ???)许可证文本的未知文件。

我不需要文件夹对话框,我只想在变量中使用工作路径。

1 个答案:

答案 0 :(得分:1)

变量名“path”是问题所在。将其更改为“workingDir”解决了这个问题。