If you are new to scripting for Photoshop, please view our Photoshop
Scripting Basics tutorial for an introduction to Photoshop scripting and a few exercises
about basic JavaScript.
What if we have several opened documents and want to choose only one of them to be closed? Documents
are identified by the ordered they were opened in. Open several files inside Photoshop and click on
the Window menu. We'll notice that the documents shown on the bottom of the menu are sorted by the
order that they were opened in. The top document is document 0 and the ones below it are document 1,
document 2, etc. You may also switch to different documents based on the the file name, including the
extension (ex. my_photoshop_file.PSD).
1. To begin, we'll try out a simple way of switching
documents. First lets type in a basic code that creates 3 documents with different sizes:
For a better understanding of the above code, please read the Opening and Closing Documents tutorial. |
||
| |
||
| 2. To switch documents, simply type in "activeDocument
= documents[]". You can select which file to open entering filename inside the square brackets
[]. An example of selecting an active document using a filename is "activeDocument = document[my_photoshop_file.psd]".
Another way is to set the active document by the order number. The order number is simply the order
that the document was opened in. Have a look at the diagram below for examples.
The code can be entered on its own line and it'll be run.
Save the script and run it in Photoshop. With the script below, 3 windows should open and the 640x480 document should be the active window on top of all the other windows. |
||





More Photoshop: