Skip to main content
Known Participant
August 21, 2023
Answered

scripting for Photoshop (how to write Javascript code to "open" a file, and "save as")

  • August 21, 2023
  • 2 replies
  • 3101 views

Hi guys,

I am new to scripting for Photoshop. I am using Javascript.

How do I write code in Javascript to open a file (e.g. a jpeg) in Photoshop? And how do I write code to save it as e.g. a PSD, EPS etc?

Will really appreciate the help.

Thanks.

This topic has been closed for replies.
Correct answer Davide_Barranca12040269

As my previous post advised, searching the Adobe Photoshop forum for a scripting keyword will deliver a wealth of working code examples.

 

The other main scripting site with code to learn from is:


https://www.ps-scripts.com/

 

As for books, legacy ExtendScript and the new UXP is exhaustively covered by:

 

https://www.davidebarranca.com

https://www.ps-scripting.com/


Thanks Stephen, let me give @Joseph25509234xr72 some extra-context.

The scripting code in the replies above is ExtendScript (an Adobe-proprietary flavour of JS based on a very old language specification). Since late 2020, Photoshop has been transitioning to UXP, which uses modern JavaScript. ExtendScript is going to be faded out (ETA not available), in favour of UXP. Please note: the two are not compatible with each other.

I have a series of videos available on YouTube for free about UXP, if you want to get started. For a more curated learning path, in late 2023 I've published a 326-page book on the subject; Marc Autret (a fine InDesign developer) has written a detailed, independent review which you can read here if you're interested.
Adobe is generally good with Reference documentation, not so much with narrative content; I'm trying to fill the gap. 

 

2 replies

Stephen Marsh
Community Expert
Community Expert
August 22, 2023

@Joseph25509234xr72 – When first startng scripting (and even today), I often struggled with the official docs, I found them useful to dissect example code, but had major issues using them to write code from scratch.

 

Searching this forum for keywords such as:

 

.saveAs(

 

or

 

 
or
 
 
or
 
 
or
 
 
Will help you to find full working code examples which may help in addition to the docs.
 
Known Participant
August 25, 2023

@Stephen Marsh 

 

I have really been struggling with this. The official docs usually just give the format, but not many practical examples.

I got frustrated to the point I decided to just post here in the community for help.

 

Thanks alot

c.pfaffenbichler
Community Expert
Community Expert
August 21, 2023

It depends on whether you want to use Document Object Model- or Action Manager-code. 

 

This pdf should cover the DOM-methods (for document in the case of saving as, for application in the case of opening a file). 

photoshop-javascript-ref-2020.pdfGitHubhttps://github.com › blob › master › Documentation

Known Participant
August 22, 2023

Thanks alot! Let me try it out.