fred
June 13, 2024, 3:40pm
1
Hi, once the user gets a folder with the file picker, is it possible to programaticaly open other files within the same path? How do I create the createSessionToken with a relative path? For example:
user picks “parent/file/pic.jpg”
later open programmaticaly: “parent/otherFile/otherPic.jpg”
const myFolder = await fs.getFolder();
const myEntry = await myFolder.getEntries();
for (const entry of myEntry) {
await batchPlay([{
_obj: "placeEvent",
linked: true,
"target": {
_path: await fs.createSessionToken(myEntry),
_kind: "local",
},
}
], {});
fred
June 14, 2024, 3:57pm
2
Working solution with fs.getEntryWithUrl():
const photoshop = require("photoshop");
const { app, constants} = photoshop;
const { showAlert } = photoshop.core;
const {batchPlay} = require("photoshop").action;
const fs = require('uxp').storage.localFileSystem;
try {
// create a new doc
const doc = app.documents.add({height:960,width:540,resolution:72,name:"mainDoc"});
// THIS WORKS BY ITSELF (WITHOUT FILE PICKER)
// const pic = await fs.getEntryWithUrl(`/Users/user/Documents/UXP/UXP_Tutorials/BatchPlay/_img/myImage.jpg`)
// FILE PICKER
const myFolder = await fs.getFolder();
await showAlert(`myFolder: ${myFolder.nativePath}`);
const pic = await fs.getEntryWithUrl(`${myFolder.nativePath}/_img/myImage.jpg`)
await batchPlay([{
_obj: "placeEvent",
linked: true,
"target": {
_path: await fs.createSessionToken(pic),
_kind: "local",
},
}
], {});
}
catch (e) {
showAlert(e)
debugger;
}