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
  • 3041 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
January 23, 2024

@Stephen Marsh Is there another resource I can use to learn adobe scripting other than the official documents? e.g. books, online courses, youtube tutorials?

Stephen Marsh
Community Expert
Community Expert
January 24, 2024

@Stephen Marsh Thanks so much for this!


You're welcome @Joseph25509234xr72 

 

I found it hard to learn without a specific goal.

 

Start small, pick one simple thing that you can do via the GUI or an action and then learn how to do it via scripting.

 

It could be opening or saving a file in another format. It could be adding, removing or renaming a layer or running a filter. It doesn't really matter! Just do one thing. Knowledge and experience will build upon itself. Before you know it, you will be scripting two things, then more!

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.