Highlighted

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

New Here ,
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.

 

Adobe Community Professional
Correct answer by Stephen_A_Marsh | Adobe Community Professional

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!');
}

 

 

TOPICS
Actions and scripting, How to

Views

80

Likes

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

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

New Here ,
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.

 

Adobe Community Professional
Correct answer by Stephen_A_Marsh | Adobe Community Professional

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!');
}

 

 

TOPICS
Actions and scripting, How to

Views

81

Likes

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
Nov 05, 2020 0
Adobe Community Professional ,
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!');
}

 

 

Likes

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
Reply
Loading...
Nov 07, 2020 0
Adobe Community Professional ,
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).

 

Likes

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
Reply
Loading...
Nov 07, 2020 0
Adobe Community Professional ,
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);

 

 

Likes

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
Reply
Loading...
Nov 07, 2020 0
New Here ,
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?

Likes

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
Reply
Loading...
Nov 08, 2020 0
Adobe Community Professional ,
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.

Likes

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
Reply
Loading...
Nov 08, 2020 1
New Here ,
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!

Likes

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
Reply
Loading...
Nov 08, 2020 0
Adobe Community Professional ,
Nov 08, 2020

Copy link to clipboard

Copied

Likes

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
Reply
Loading...
Nov 08, 2020 1
Adobe Community Professional ,
Nov 08, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Nov 08, 2020 0