Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
var FF= Folder(Folder.desktop + "/myFolder");
if (!FF.exists) FF.create();
Copy link to clipboard
Copied
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!");
}
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
The best person to help you may be id Davide Barranca:
Photoshop, etc. | Random thoughts on Photoshop, Coding and all the rest
Copy link to clipboard
Copied
I figured it out.
The File and Folder -objects are an ExtendScript -thing. They don't exist in JavaScript (at least I don't think so - as you cannot even create new empty Folder objects!)
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I ran into the same problem when trying to populate my panel from scripts in my scripts folder.
The workaround I ended up with is generating an HTML file with a JSX and then loading it into the panel.
You can find my solution here:
Copy link to clipboard
Copied
Sorry for being late to the party, but the email linked to the AdobeID which I use to reply to Forum threads isn't active anymore and I really looove those green bars below my avatar
Heimdaal​, you can use the CEP "Other API" to deal with Files and Folders!
Please check here.​
Regards,
Davide
---
Photoshop HTML Panels Development Course
Copy link to clipboard
Copied
Took me a while to figure out that ReadDir() is actually capitalized readdir(), while ReadFile() is actually capitalized readFile(), nice and consistent, Adobe.
I'm assuming this is clearer with the Extension Builder installed?
Copy link to clipboard
Copied
I wouldn't use Extension Builder, as its latest update is from 2013 I'd say. If you want to explore CEP API it's easier to attach a debugger to a Panel and play with the Chrome Developer Tools console.
Davide
Find more inspiration, events, and resources on the new Adobe Community
Explore Now