Scripting 如何修改此脚本以在打开的文件上运行TinyPNG,而不必使用“打开”对话框来选择文件?

Scripting 如何修改此脚本以在打开的文件上运行TinyPNG,而不必使用“打开”对话框来选择文件?,scripting,photoshop,tinypg,Scripting,Photoshop,Tinypg,我正试图修改这个脚本,用TinyPNG Photoshop插件压缩并关闭所有打开的文件,而不是在打开的对话框中一次选择一个文件。它们确实提供了另一个脚本,允许您压缩整个文件夹。然而,我发现自己需要在一个文件夹中压缩50个图像中的10个,所以我宁愿选择这10个,或者打开这10个,然后在所有打开的文件上运行脚本 我试着换了 压缩文件(File.openDialog(“选择要压缩的PNG或JPEG文件”) 与 压缩文件(app.activeDocument) 试图让脚本压缩当前文档 它不使用活动文档,

我正试图修改这个脚本,用TinyPNG Photoshop插件压缩并关闭所有打开的文件,而不是在打开的对话框中一次选择一个文件。它们确实提供了另一个脚本,允许您压缩整个文件夹。然而,我发现自己需要在一个文件夹中压缩50个图像中的10个,所以我宁愿选择这10个,或者打开这10个,然后在所有打开的文件上运行脚本

我试着换了

压缩文件(File.openDialog(“选择要压缩的PNG或JPEG文件”)

压缩文件(app.activeDocument)

试图让脚本压缩当前文档

它不使用活动文档,而是直接跳转到catch(错误)

compressFile()
需要
File
对象,而
activeDocument
document
对象

对于打开的文档,您需要在文档中循环:

for (var i = documents.length - 1; i >= 0; i--) {
    activeDocument = documents[i];
    compressFile()
}
compressFile()
中,您应该删除
opener
部分(因为所有文档都已打开),但您需要用实际文档路径替换
文件

    // Compress the document
    var tinify = new ActionDescriptor();
    tinify.putPath(charIDToTypeID("In  "), new File(activeDocument.path + "/" + activeDocument.name)); /* Overwrite original! */
    tinify.putUnitDouble(charIDToTypeID("Scl "), charIDToTypeID("#Prc"), percentage);
对于文件对话框,您只需修改
压缩文件.jsx的最后一位即可:

//dialogue to select multiple files:
var startFolder = Folder.myDocuments,
    myFiles = startFolder.openDlg(void(0), void(0), true);

if (myFiles != null) //if the dialogue wasn't cancelled
{
    //launch compressFile for every selected file
    for (var i = myFiles.length - 1; i >= 0; i--)
    {
        compressFile(myFiles[i])
    }
}
compressFile()
需要
File
对象,而
activeDocument
document
对象

对于打开的文档,您需要在文档中循环:

for (var i = documents.length - 1; i >= 0; i--) {
    activeDocument = documents[i];
    compressFile()
}
compressFile()
中,您应该删除
opener
部分(因为所有文档都已打开),但您需要用实际文档路径替换
文件

    // Compress the document
    var tinify = new ActionDescriptor();
    tinify.putPath(charIDToTypeID("In  "), new File(activeDocument.path + "/" + activeDocument.name)); /* Overwrite original! */
    tinify.putUnitDouble(charIDToTypeID("Scl "), charIDToTypeID("#Prc"), percentage);
对于文件对话框,您只需修改
压缩文件.jsx的最后一位即可:

//dialogue to select multiple files:
var startFolder = Folder.myDocuments,
    myFiles = startFolder.openDlg(void(0), void(0), true);

if (myFiles != null) //if the dialogue wasn't cancelled
{
    //launch compressFile for every selected file
    for (var i = myFiles.length - 1; i >= 0; i--)
    {
        compressFile(myFiles[i])
    }
}

此错误是功能问题的原因。如果您的函数需要图像,则您不能简单地将activeLayer用作imagedata。因此,如果您需要解决方案,请向我们提供compressFile函数:),然后我们可能会为您修复此错误。此错误是功能问题的原因。如果您的函数需要图像,那么您不能简单地将activeLayer用作图像数据。所以,如果您需要解决方案,请为我们提供压缩文件函数:),然后我们可能会为您修复它