I would recommend that you use a file- or folder-selection dialog to determine the files you want to process, then have the Script work from that.
Determining the Folder in which the open file resides is of course possible but when addressing the files in the folder one may have to exclude the open image to avoid double processing …
// 2014, use it at your own risk;
// select files;
if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog ("please select files", '*.jpg;*.tif;*.pdf;*.psd;*.bmp', true)}
else {var theFiles = File.openDialog ("please select files", getFiles, true)};
if (theFiles.length > 0) {
for (var m = 0; m < theFiles.length; m++) {
var theImage = app.open(File(theFiles[m]));
/* insert your operations here */
}
};
////// get psds, tifs and jpgs from files //////
function getFiles (theFile) {
if (theFile.name.match(/\.(eps|ai|jpg|tif|psd|pdf|)$/i)) {
return true
};
};