Copy link to clipboard
Copied
I know how to open a single file from a dialog (code snippet):
var selectFile = app.openDialog();
I also know how to open a folder and get all the files in that top-level folder (code snippet):
var selectFolder = Folder.selectDialog("select folder");
However, I can't find or work out how to have the user select multiple files (but not all files). Can somebody please enlighten me? Thank you in advance!
Does this help?
var aFile = selectFile(true)
alert (aFile.join("\n"));
////////////////////////////////////
////////////////////////////////////
////////////////////////////////////
////// select file //////
function selectFile (multi) {
if (multi == true) {var theString = "please select files"}
else {var theString = "please select one file"};
if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog (theString, '*.jpg;*.tif;*.psd;*.png', multi)}
else {var theFiles = File.openDialog (th
...
If you only work on one platform you can limit the code considerably, on windows it comes down to
var theFiles = File.openDialog (theString, '*.jpg;*.tif;*.psd;*.png', true)
I guess.
A few weeks ago I needed this feature and found something that solved my problem on a javascript forum on the internet.
For me he decided:
selectFile = File.openDialog("please select files", Multiselect = true);
alert(decodeURI(selectFile))
Copy link to clipboard
Copied
Does this help?
var aFile = selectFile(true)
alert (aFile.join("\n"));
////////////////////////////////////
////////////////////////////////////
////////////////////////////////////
////// select file //////
function selectFile (multi) {
if (multi == true) {var theString = "please select files"}
else {var theString = "please select one file"};
if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog (theString, '*.jpg;*.tif;*.psd;*.png', multi)}
else {var theFiles = File.openDialog (theString, getFiles, multi)};
////// filter files for mac //////
function getFiles (theFile) {
if (theFile.name.match(/\.(jpg|tif|psd|png)$/i) || theFile.constructor.name == "Folder") {
return true
};
};
return theFiles
};
Copy link to clipboard
Copied
Thank you, it might help when I can give it some time, I'm going to have to work at it though as it is not "out of the box". At least I can see that unlike opening a file or a folder full of files, it is not cross-platform and is more complex than 1-3 lines of code.
Copy link to clipboard
Copied
If you only work on one platform you can limit the code considerably, on windows it comes down to
var theFiles = File.openDialog (theString, '*.jpg;*.tif;*.psd;*.png', true)
I guess.
Copy link to clipboard
Copied
Thank you c.pfaffenbichler for you reply, I got there in the end using the same loop as in my reply to Shulipa. Some many wasted hours, but I'm "happy" now!
/* open selected files from folder */
var aFile = selectFile(true);
for (var i = 0; i < aFile.length; i++) {
open(File(aFile[i]));
}
////// select file //////
function selectFile(multi) {
if (multi === true) { var theString = "Please select the files:" }
else { var theString = "Please select one file" }
if ($.os.search(/windows/i) != -1) { var theFiles = File.openDialog(theString, '*.jpg;*.tif;*.psd;*.png', multi) }
else { var theFiles = File.openDialog(theString, getFiles, multi) }
////// filter files for mac //////
function getFiles(theFile) {
if (theFile.name.match(/\.(jpg|tif|psd|png)$/i) || theFile.constructor.name == "Folder") {
return true;
}
}
return theFiles
}
Copy link to clipboard
Copied
A few weeks ago I needed this feature and found something that solved my problem on a javascript forum on the internet.
For me he decided:
selectFile = File.openDialog("please select files", Multiselect = true);
alert(decodeURI(selectFile))
Copy link to clipboard
Copied
Thank you Shulipa Bernad for your reply!
You wouldn't believe how many hours it took me to make that work, I don't "know" JS so it can take me some time and a lot of frustration to get there!
The following appears to work on both Mac and Win:
selectFile = File.openDialog("Please select the file/s:", Multiselect = true);
for (var i = 0; i < selectFile.length; i++) {
var openFiles = app.open(File(selectFile[i]));
}
My next stumbling block is getting .sort to work correctly...
Copy link to clipboard
Copied
What kind of array are you trying to sort?
Copy link to clipboard
Copied
The list of items from the File.openDialog step... Whether it is .sort(); or .sort.reverse(); it would be helpful to have the option in there. I have been trying with both your function or with the shorter code from Shulipa without success.
Copy link to clipboard
Copied
That is an array of the selected files’ paths as strings? Are they all located in the same folder?
Are you just trying to sort them alphabetically or according to something else?
Copy link to clipboard
Copied
OK, I'm starting to get an inkling here when you mention path that it is not as easy as I was hoping...
Yes, all in the same source directory. For example:
file001.jpg
file002.jpg
file003.jpg
If one introduced a variableName.sort.reverse(); the expectation is that the processed files would open in the reverse order:
file003.jpg
file002.jpg
file001.jpg
I always like to explicitly consider sort order as Mac and Win may handle this in different ways if not explicitly set.
Copy link to clipboard
Copied
wrong topic, sorry!
Copy link to clipboard
Copied
Please send me a screen recording
Copy link to clipboard
Copied
Please send me a screen recording
By @Manoj32824813540j
You have replied to a 3-year-old topic with an incomplete sentence.