• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to create a script to open files with the same name

Explorer ,
Nov 05, 2020 Nov 05, 2020

Copy link to clipboard

Copied

And guys, help me.

I have a Jpg file open in Photosop and in the same folder where this file is located I have a file of the same name but with the PSD format I would like to know if there is any script so that when I open the jpg file it will search in the same folder by the file on PSd and open.

 

TOPICS
Actions and scripting

Views

769

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 07, 2020 Nov 07, 2020

The following code will work on an open (previously saved) document:

 

 

// Open PSD File with Same Name As Open Doc.jsx
// 2020 - Stephen_A_Marsh

/* https://community.adobe.com/t5/photoshop/how-to-create-a-script-to-open-files-with-the-same-name/td-p/11571441?page=1 */

#target photoshop

if (app.documents.length > 0) {

    var targetDocName = app.activeDocument.name.replace(/\.[^\.]+$/, '.psd'); // presumes a lowercase PSD extension
    var otherFile = app.activeDocument.path.fsName + '/' + 
...

Votes

Translate

Translate
Adobe
Community Expert ,
Nov 07, 2020 Nov 07, 2020

Copy link to clipboard

Copied

The following code will work on an open (previously saved) document:

 

 

// Open PSD File with Same Name As Open Doc.jsx
// 2020 - Stephen_A_Marsh

/* https://community.adobe.com/t5/photoshop/how-to-create-a-script-to-open-files-with-the-same-name/td-p/11571441?page=1 */

#target photoshop

if (app.documents.length > 0) {

    var targetDocName = app.activeDocument.name.replace(/\.[^\.]+$/, '.psd'); // presumes a lowercase PSD extension
    var otherFile = app.activeDocument.path.fsName + '/' + targetDocName;
    openOtherFile = File(otherFile);
    open(openOtherFile);

} else {
    alert('Open PSD File with Same Name As Open Doc.jsx' + '\r' + 'You must have a document open to run this script!');
}

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2020 Nov 07, 2020

Copy link to clipboard

Copied

You can use the previous code in the Open event in the File > Scripts > Scripts Events Manager so that every time you open a file it will check for a .psd file of the same name in the same directory and automatically open it for you.

 

Screen Shot 2020-11-08 at 10.58.52.png

 

One could of course add an extra condition to alert if no matching file was found, or to perhaps open the first file using a file open dialog window rather than using a already open file (see code below).

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2020 Nov 07, 2020

Copy link to clipboard

Copied

This variation on the previous script offers the File > Open dialog window to select a single file to open rather than using the active document (don't select multiple files unless you want an error):

 

 

// Open PSD File with Same Name As Open Doc via Open Dialog.jsx
// 2020 - Stephen A Marsh

/* https://community.adobe.com/t5/photoshop/how-to-create-a-script-to-open-files-with-the-same-name/td-p/11571441?page=1 */

#target photoshop

// Use the File > Open dialog to open the file
var selectFile = app.openDialog();
openFile = File(selectFile);
open(openFile);
var targetDocName = app.activeDocument.name.replace(/\.[^\.]+$/, '.psd'); // presumes a lowercase PSD extension
var otherFile = app.activeDocument.path.fsName + '/' + targetDocName;
openOtherFile = File(otherFile);
open(openOtherFile);

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 08, 2020 Nov 08, 2020

Copy link to clipboard

Copied

Soooo thank you my friend. saved me! It worked! Would you like to ask to open via ACR?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2020 Nov 08, 2020

Copy link to clipboard

Copied

I hope that the script is useful for you. Thanks for marking one of my replies as the correct answer.

 

I'm a little confused, do you mean that you would like to automatically open the .psd file in the Adobe Camera Raw plug-in, rather than Photoshop?

 

Or do you mean that once the .psd is automatically opened in Photoshop, apply the Camera Raw Filter (are these single layer files)?

 

The ACR plug-in is intended for raw camera files, however, it does have support for JPEG/HEIC and TIFF files, but not PSD. I know that this can be forced on the Mac, not sure about Windows or if this is scriptable.

 

I think that more information is required.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 08, 2020 Nov 08, 2020

Copy link to clipboard

Copied

Thanks for the help ... With your script I created another one on top and managed to open it directly in ACR! You are amazing!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2020 Nov 08, 2020

Copy link to clipboard

Copied

LATEST

Please do share your script, I'd like to see what you came up with!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 08, 2020 Nov 08, 2020

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines