Skip to main content
Participant
August 3, 2024
Answered

learning scripting with javascript create file

  • August 3, 2024
  • 1 reply
  • 783 views
I'm learning scripting in photoshop and using the scripting guide from 2020. The new File javascript doesn't create the file, and the script fails. Could it be that this is no longer supported? Is there other way to create a file?
I will try to test on a windows machine o see if there is any difference.

 

var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;


filePath = "/Users/$USERNAME/Desktop/myfile1.pdf"
var fileRef = new File(filePath);


var pdfOpenOptions =  new PDFOpenOptions
pdfOpenOptions.antiAlias = true
pdfOpenOptions.mode = OpenDocumentMode.RGB
pdfOpenOptions.resolution = 72
pdfOpenOptions.page = 3

app.open( fileRef, pdfOpenOptions )
app.preferences.rulerUnits = originalRulerUnits​

 

 

 
This topic has been closed for replies.
Correct answer Stephen Marsh

I think that there's a misunderstanding in your expectations. That's the correct and expected result of the test. False is the result if there is no file at the path of the file object. The new File() is a programming object used to work with a literal file, not a method to create a literal file. To create a literal file, you would need to create a new document and save it using the appropriate file format save options.

1 reply

Stephen Marsh
Community Expert
Community Expert
August 4, 2024

Try changing this:

 

filePath = "/Users/$USERNAME/Desktop/myfile1.pdf"
var fileRef = new File(filePath);

 

To this:

 

filePath = "~/Desktop/myfile1.pdf";
var fileRef = new File(filePath);
alert(fileRef.exists);

 

What is the result of the alert?

 

https://theiviaxx.github.io/photoshop-docs/Core/File.html

 

Participant
August 4, 2024

I tried to run it and getting False.  I also checked the path of Desktop and the file wasn't created.

 

I tried search extend script on Mac and there seem to be some limitations. I used VS code to run extend scipt with small tool someone developed. I can't run the official extend script debugger because it only suppport Intel chips. My machine it too weak to run Rosetta with VSCODE which would probably solved this problem.. 

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
August 4, 2024

I think that there's a misunderstanding in your expectations. That's the correct and expected result of the test. False is the result if there is no file at the path of the file object. The new File() is a programming object used to work with a literal file, not a method to create a literal file. To create a literal file, you would need to create a new document and save it using the appropriate file format save options.