Script to add filename to file info?

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Coinneach
Posts: 2
Joined: Tue Aug 23, 2022 2:56 pm

Script to add filename to file info?

Post by Coinneach »

Hi,
Many years ago I received help from someone on a forum very much like this one.
My request was for a script to copy the filename of an image and write it into the "File Info"
My habit was to open an image, process/retouch it and save the file with a more meaningful name, rather than the camera filename.

I obtained said script and over the years it proved very valuable as I could go to File Info and find the file name of the original image. This means that I can find the file to reprocess without trying to remember which shoot out of almost 20 years of images in my archive.

So, Can someone please help me by recreating this script that I have lost during some computer upgrade or other over the past couple of years.

TLDR;
I'd like a script to write the current filename into either the Document Title or Description in the Basic tab in File Info


Thanks in advance

Kenny
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Script to add filename to file info?

Post by Kukurykus »

'PreservedFileName' field is more correct for original name. It can be obtained from File Properties in Raw Data of XMP Metadata.

Write to:

Code: Select all

!ExternalObject.AdobeXMPScript && ExternalObject
.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
(meta =  new XMPMeta((xmp = (aD = activeDocument).xmpMetadata).rawData))
.setProperty('http://ns.adobe.com/xap/1.0/mm/', 'PreservedFileName',
aD.name), xmp.rawData = meta.serialize()
Read from:

Code: Select all

!ExternalObject.AdobeXMPScript && ExternalObject
.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
(meta = new XMPMeta((activeDocument.xmpMetadata).rawData))
.doesPropertyExist(ns = 'http://ns.adobe.com/xap/1.0/mm/',
pm = 'PreservedFileName') && meta.getProperty(ns, pm).value
Coinneach
Posts: 2
Joined: Tue Aug 23, 2022 2:56 pm

Re: Script to add filename to file info?

Post by Coinneach »

Wow, thank-you Kukurykus.

I wonder if you can advise me how to make use of these scripts.

I have almost zero knowledge of scripting

Thanks

Kenny
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Script to add filename to file info?

Post by Kukurykus »

The same as you used previous scripts? Save these codes to separate .jsx files, one as Reader, second as Writer. You may then copy them to 'Presets / Scripts' folder of your Photoshop, so after relaunching the application you'll have access to them from 'File / Scipts' menu.
User avatar
Scriptor
Posts: 24
Joined: Tue Oct 01, 2019 12:07 pm

Re: Script to add filename to file info?

Post by Scriptor »

Another method, might be a bit cleaner depending on how you implement it:

Code: Select all

app.activeDocument.info.title = app.activeDocument.name; //Adds the current document name to the IPTC Core field "Title"
app.activeDocument.info.caption = app.activeDocument.name; //Adds the current document name to the IPTC Core field "Description"

//Then when you're done:
app.activeDocument.close(SaveOptions.SAVECHANGES);
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Script to add filename to file info?

Post by Kukurykus »

This is what he asked for indeed, but I avoided to provide this method as it was used due to lack of his knowledge of something more appropriate.
User avatar
Scriptor
Posts: 24
Joined: Tue Oct 01, 2019 12:07 pm

Re: Script to add filename to file info?

Post by Scriptor »

Kukurykus wrote: Thu Aug 25, 2022 9:01 am The same as you used previous scripts? Save these codes to separate .jsx files, one as Reader, second as Writer. You may then copy them to 'Presets / Scripts' folder of your Photoshop, so after relaunching the application you'll have access to them from 'File / Scipts' menu.
You can also, instead of placing the .jsx-files in your "Presets/Scripts"-folder in Photoshop, just place them wherever and create an action that you name to "Reader", then select "Record", File > Scripts > Browse..., and then select the .jsx-file. Then stop the recording, and play the action again whenever you want to play the script.
Kukurykus wrote: Sat Sep 10, 2022 10:47 am This is what he asked for indeed, but I avoided to provide this method as it was used due to lack of his knowledge of something more appropriate.
That's a good reason. However if anyone else with more knowledge faces the same problem, I don't see any problem with providing them with more solutions:)