Skip to main content
Inspiring
June 30, 2016
Question

Unable to create Folder -object in JS - only works in JSX

  • June 30, 2016
  • 1 reply
  • 1416 views

I'm making a Photoshop panel and I have a drop-down menu that I want to populate with elements based on the number of files in a folder. However, for reasons unknown to me I seem to be completely unable to create Folder-objects in the javascript file. I've tested the below three lines of code both in my JSX file and my JS file. In the JSX one it works as it should: I get an alert dialog printing out the temp/dummy name of the folder. In JS though the entire script comes to a halt after the row creating the folder. Why is this?

alert("trying to make folder...");

var lol = new Folder();

alert(lol);

This topic has been closed for replies.

1 reply

Pedro Cortez Marques
Legend
June 30, 2016

var FF=  Folder(Folder.desktop + "/myFolder");

if (!FF.exists) FF.create();

HeimdaalAuthor
Inspiring
June 30, 2016

Specifying a path changes nothing for me - the object is still not created, instead the code comes to a halt before the second alert. Also doing theFolder.create() does nothing either

EDIT: I even tried hardcoding the folder path and also make sure that the folder didn't exist already, but for reasons unknown the Folder-object is still not created.

fontAbsPath = "c:/Users/martin.dahlin/Desktop/Test/";

alert("trying to make folder... fontAbsPath is:\n" + fontAbsPath); // This is correct

var fontFolder = new Folder(fontAbsPath); // Script HALTS here! :(

if(!fontFolder.exists){

    alert("created folder because it didn't exist");

    fontFolder.create();

}else{

    alert("didn't create the folder because it already exists!");

}

HeimdaalAuthor
Inspiring
July 1, 2016

It baffles me that the very same code works in JSX but not in JS.

I noticed one difference though:
The place where the Folder creation fails is inside a callback function of CSInterface.evalScript()

var csInterface = new CSInterface();

var extensionId =  csInterface.getExtensionID();

function init(){

    themeManager.init();

    // Event listener for PhotoshopJSONCallback

    csInterface.addEventListener("com.adobe.PhotoshopJSONCallback" + extensionId, PhotoshopCallbackUnique);

    // The callback for the event listener

    function PhotoshopCallbackUnique(csEvent){

        try{

            if (typeof csEvent.data === "string"){

                var eventData = csEvent.data.replace("ver1,{", "{");

                var eventDataObject = JSON.parse(eventData);

                csEvent.data = eventDataObject;

                // Retrieve metadata and update controls

                csInterface.evalScript("myFunc()", function(result){

                    // Code

                    var fontFolder = new Folder(getMetadata("c:/Users/martin.dahlin/Desktop/Test/")); // Test

                    alert("created Folder object - it is:\n" + fontFolder); // Code halts here!!!

                   

                    // Rest of the code


EDIT: Moved the Folder creation inside it's own function and it STILL fails. Creating folders in the JS file appears to be a big no-no.

EDIT2: Even with the below code outside the init() in the JS-file breaks down the entire panel:

var test = new Folder("c:/Users/martin.dahlin/Desktop/Test/");

alert(test);