Howdy!
I’m trying to find a usage example for the Path module (as documented in the UXP Javascript reference), specifically how to access it. I tried:
window.Path
as well as
require("path")
Neither did the job. If someone out there has had luck using this module I’d be super curious to find out how
Thanks in advance!
sttk3
2
According to @shuji, path variable can be used without any declaration.
const pathText = `file:/Users/username/Desktop/filename.txt` ;
const parentFolder = path.dirname(pathText) ;
console.log(parentFolder) ; // --> file:/Users/username/Desktop
const nameWithoutExtension = path.parse(pathText).name ;
console.log(nameWithoutExtension) ; // --> filename
Here I made an example of how to get the directory, create a subfolder and save the active document with jpg extension.
try {
const path = app.activeDocument.path.replace(/\\[^\\]*$/, "")
const Entrada = await fs.getEntryWithUrl(`file:${path}`);
const entries = await Entrada.getEntries();
let subfolder = entries.filter((entry) => entry.isFolder).find((subFolder) => subFolder.name === "SubFolder");
if (!subfolder) {subfolder = await Entrada.createFolder("SubFolder");}
newFileName = app.activeDocument.name;
var myFile = await subfolder.createFile(newFileName, { overwrite: true });
let jpegOptions = {
quality: 100,
embedColorProfile: true
}
app.activeDocument.saveAs.jpg(myFile, jpegOptions, true);
} catch (err) {alert(err)}
You can get more details in this dicursion Save Batch Images with Dynamic Name in Photoshop UXP