Can I open a Photoshop file with UXP?

Hey, guys! Hope someone can give me some help with this issue…

A few months ago I’ve created this crazy “Diversity Generator” script for Photoshop: https://www.behance.net/gallery/92286407/Diversity-Generator-Free-Photoshop-Script

The problem with it is that, since this is a script, I must ask for the user to open a Photoshop File, that I provide along with the script. I was wondering if using UXP I could include this file with my Plugin, this way the user wouldn’t need to do it by themselves. Is this possible?

If the answer is yes, how could I open a Photoshop File using UXP?

Thank you! :smiley: I’ll try to be more present in these forums, even being just a newbie when it comes to development haha…

Yup!

The photoshop object supplies an open method that you can use to open a document. Since the document would be in your plugin’s folder, you can access it using getPluginFolder():


async function openTemplate() {
    const fs = require("uxp").storage.localFileSystem;
    const pluginFolder = await fs.getPluginFolder();
    const theTemplate = await pluginFolder.getEntry("yourFile.psd");
    
    const app = require("photoshop").app;
    await app.open(theTemplate);
}

1 Like

OMG! It worked perfectly. :smiley:

Thank you. You’re always awesome… haha
I’ll improve my script and make it a Plugin. :heart_eyes:

1 Like

Hi @kerrishotts,
How would I go about getting a file from a subfolder of the pluginFolder?

I’ve created a subfolder to hold my photoshop template files and I’ve tried a few things to access that subfolder without any luck. Any clues?

I’ve tried await pluginFolder.getEntry('/subfolder/template.psd') but that crashes PS.
Do I have to use BatchPlay?

John

Nevermind. I found another post with the answer. I just had to remove the first forward slash. :roll_eyes:

Thanks anyway.

1 Like

Do you have the crash log(s)/error messages when using the leading slash?

I’ve tried recreating the crash but can’t replicate it now. I was a bit frustrated with my code at the time so it could have been something completely unrelated and I didn’t notice it.

John