Skip to main content
Inspiring
February 18, 2025
Question

uxp open file in photoshop mac not working

  • February 18, 2025
  • 1 reply
  • 473 views

@sttk3 

@Stephen

 

I created a button in the uxp panel that needs to open files from a folder,

to my surprise I am having a problem open file in photoshop mac does not work.

this is what came out of the action, copy javascript.

 

async function OpenFile() {
    let result;
    let psAction = require("photoshop").action;

    let command = [
        // Apri
        {"descriptor": {"_obj":"open"}, "options": {"dialogOptions": "display"}}
    ];
    result = await psAction.batchPlay(command, {});
}

async function open_file() {
    await require("photoshop").core.executeAsModal(OpenFile, {"commandName": "Action Commands"});
}

await open_file();

 

1 reply

Legend
February 19, 2025

Since open exists as a Photoshop function, you can use it directly instead of batchPlay.

 

## If you let the user specify a file to open in a dialog

No specific permissions are needed to open a file. Just pass the chosen file (Entry) to open.

 

## If you want programmatically specify a file without GUI operation by the user
Appropriate permissions are required to open the file, write `“localFileSystem”: “fullAccess”` in requiredPermissions of manifest.json.

 

Then, generate an Entry from the file path string using getEntryWithUrl and pass it to open.

Inspiring
February 19, 2025

Thanks for the info The manifest is fine, I had already entered full access to the files, From what I read I can only open a file that I select, If I wanted to open 10 I have to add a few more strings.

Inspiring
February 19, 2025

I found this piece of code that does what I want,
but when I open the raw files, instead of opening them in camera raw it opens them directly in photoshop.
you can change this option.

const { app, core } = require("photoshop");
const fs = require('uxp').storage.localFileSystem;

const openFiles = async () => {
  await core.executeAsModal( async () => {
    const entry = await fs.getFolder();
    const token = await fs.createPersistentToken(entry);
    localStorage.setItem("persistentFolder", token);
    
    const thePersistentFolderToken = localStorage.getItem("persistentFolder");
    const thePersistentFolder = await fs.getEntryForPersistentToken(thePersistentFolderToken);
    // show all files
    const files = await thePersistentFolder.getEntries();
  
    for (const file of files) {
      await app.open(file)
    }    
  })
}

openFiles();