Copy link to clipboard
Copied
hi all,
how can we open the file from the file path using script or action.
please help me to get this.
Thank You
Then you need to loop over the input files.
I'll post some code as an example...
EDIT: here is one way to open a folder of files and filter by file type and sort or reverse sort:
#target photoshop
// Set the input folder
var inputFolder = Folder.selectDialog("Please select the input folder:");
// Limit the input files, add or remove extensions as required
var fileList = inputFolder.getFiles(/\.(webp|tif|tiff|jpg|jpeg|psd|psb|png)$/i);
//fileList.sort().reverse();
fileList...
Copy link to clipboard
Copied
For an action, just record the step of opening a file. That being said, actions are tricky when it comes to file paths. They are platform dependent and often dependent on the computer recording the action.
One way to open from a static path using scripting:
var theFilePath = "~/Desktop/image001.jpg";
open(File(theFilePath));
// or
open(File("~/Desktop/image001.jpg"));
Or via a dialog:
var selectFile = File.openDialog("Please select the file:");
open(selectFile);
// or
var selectFile = app.openDialog();
open(File(selectFile));
// or
executeAction(stringIDToTypeID("open"), new ActionDescriptor(), DialogModes.NO);
Copy link to clipboard
Copied
hi @Stephen Marsh
what i want is i have one folder which have 100 document. so it should automatically open the file and close the file without saving.
Thank You
Copy link to clipboard
Copied
hi @Stephen Marsh
what i want is i have one folder which have 100 document. so it should automatically open the file and close the file without saving.
Thank You
By @Mahesh12
Script automation generally requires you to "do something" in-between opening and closing a file... Otherwise, why bother?
To close an open file without saving (wrapped in a try/catch so that a conditional check for an open doc isn't required):
try {
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
} catch (e) {}
So I don't know what else you need, this isn't really complete code.
What do you need to do between opening a file and closing it without saving?
Copy link to clipboard
Copied
hi @Stephen Marsh
when i open the document i will retrieve some data from the active document and after retrieving i want to close the the document without saving.
Copy link to clipboard
Copied
Then you need to loop over the input files.
I'll post some code as an example...
EDIT: here is one way to open a folder of files and filter by file type and sort or reverse sort:
#target photoshop
// Set the input folder
var inputFolder = Folder.selectDialog("Please select the input folder:");
// Limit the input files, add or remove extensions as required
var fileList = inputFolder.getFiles(/\.(webp|tif|tiff|jpg|jpeg|psd|psb|png)$/i);
//fileList.sort().reverse();
fileList.sort();
var savedDisplayDialogs = app.displayDialogs;
app.displayDialogs = DialogModes.NO;
// Set the file processing counter
var fileCounter = 0;
// Forward loop over the input files
for (var i = 0; i < fileList.length; i++) {
open(fileList[i]);
/*
YOUR CODE HERE
*/
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
fileCounter++;
}
app.displayDialogs = savedDisplayDialogs;
alert('Script completed!' + '\n' + fileCounter + ' files processed!');
This variation allows one to manually select one or more files to process (instead of processing a folder):
#target photoshop
(function () {
// Select the files
var selectFiles = File.openDialog("Please select the file or files:", Multiselect = true);
if (selectFiles === null) {
//alert("Script cancelled!");
return;
}
//selectFiles.sort().reverse();
selectFiles.sort();
var savedDisplayDialogs = app.displayDialogs;
app.displayDialogs = DialogModes.NO;
// Set the file processing counter
var fileCounter = 0;
// Forward loop over the input files
for (var i = 0; i < selectFiles.length; i++) {
open(selectFiles[i]);
/*
YOUR CODE HERE
*/
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
fileCounter++;
}
app.displayDialogs = savedDisplayDialogs;
alert('Script completed!' + '\n' + fileCounter + ' files processed!');
})();
Copy link to clipboard
Copied
Have you considered using scripts like Image Processor Pro to make your life easier? It can open each file from a folder without a single line of code. During batch processing, you can run actions to accomplish whatever task you want and close the file without saving.
Maybe we can better assist you if you can explain entire process and scope of batch.
Copy link to clipboard
Copied
Please don’t forget to mark @Stephen Marsh ’s post as »Correct Answer« or, if something should be missing, elaborate on the exact task.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more