I'm trying to modify this script to compress and then close all the opened files with the TinyPNG Photoshop plugin as opposed to having to choose one file at a time in an open dialog box. They do offer another script that allows you to compress a whole folder. However, I find myself needing to compress 10 out 50 images in a folder so I'd rather just be able to select those 10 or to open those 10 and run the script on all open files.
I've tried replacing
compressFile(File.openDialog("Choose a PNG or JPEG file to compress")
with
compressFile(app.activeDocument)
in an attempt to have the script just compress the current document.
Instead of using the active document it simply skips to the catch(error).
try {
// Compress Active File
compressFile(File.openDialog("Choose a PNG or JPEG file to compress"));
} catch(error) {
alert("No JPEG or PNG file selected or compression error.");
}
compressFile()
requires aFile
object whileactiveDocument
is adocument
object.For opened documents you'll want a loop through the documents:
and in
compressFile()
you should get ridopener
part (because all the documents are already opened) but you'll need to replace afile
with actual document path:For a files dialogue you can simply modify the last bit of
Compress File.jsx
: