Show folder content in custom context menu

Ah you are right, sorry I remembered that incorrectly.

You could however switch to a different command like ls for simple lists of files:

async function retrieveJSON() {
    let folder = "/Users/andreas/Documents";
  
    // Construct the shell script to recursively list all files using ls
    let script = `ls "${folder}"`;
  
    let filePaths = await runShellScript({
      script: script,
    });
  
    // Split the file paths by new line
    let fileArray = filePaths.split("\n").filter(Boolean); // filter(Boolean) removes any empty lines
  
    // Create an array of objects with filePath and fileName
    let files = fileArray.map((filePath) => {
      let fileName = filePath.split("/").pop(); // Extract the file name from the path
      return { filePath, fileName };
    });
  
    let menuItems = [];
  
  
    // Create the context menu items that trigger a shell script to open the file
    for (let file of files) {
      let item = {
        title: file.fileName,
        action: `js::(async () => {runShellScript({script: 'open "${folder + '/' + file.filePath}"'})})()`,
        icon: `sfsymbol::doc.circle`
      };
      menuItems.push(item);
    }
  
    return JSON.stringify(menuItems);
  }
  

(by the way, one of the next versions will also allow to use these scripts in floating menus to dynamically retrieve their items)