Copy link to clipboard
Copied
Hello,
I'm writing a script which should change the metadata of a tif image.
This works fine
img.info.author = "Me";
img.info.city = "London";
I also want to change the creation date and according to Adobe Photoshop JavaScript Reference, the date should be in format "YYYYMMDD", but this doesn't work:
img.info.creationDate = '20000101';
I also tried different formats to no avail too:
img.info.creationDate = '2000/01/01';
img.info.creationDate = '01012000';
img.info.creationDate = '01/01/2000';
Plz help.
Thanks.
Copy link to clipboard
Copied
This is one way to do it...
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
var newDate = "2008-06-10T02:43:23";
xmp = new XMPMeta( app.activeDocument.xmpMetadata.rawData );
if( xmp.doesPropertyExist(XMPConst.NS_PHOTOSHOP, "DateCreated" ) ) xmp.deleteProperty( XMPConst.NS_PHOTOSHOP, "DateCreated" );
xmp.setProperty( XMPConst.NS_PHOTOSHOP, "DateCreated" ,new XMPDateTime(newDate));
app.activeDocument.xmpMetadata.rawData = xmp.serialize();
Copy link to clipboard
Copied
Thank you for this solution, but I was looking for dom approach as per my example (sorry I should have specified).
I'm really stuck - the property "creationDate" according to documentation is Read-write, I don't have any problem with changing any other properties I want, but "creationDate".
I'm still looking for a solution, so any help would be highly appreciated.
Thanks
Copy link to clipboard
Copied
Actually, the following works for me (Mac, CC 2015.5)
app.activeDocument.info.creationDate = "20101024"
app.activeDocument.info.creationDate; // 20101024
If you input a wrong string, it returns undefined.
Davide
Copy link to clipboard
Copied
The supplied example does not work in CS3/CS5 or CS6 don't know about newer versions though.
Good luck.
From the CS6 Javascript ref.
var theDate = new Date();
// the year is from 1900 ????
var theYear = (theDate.getYear() + 1900).toString();
// convert the month from 0..12 to 00..12
var theMonth = theDate.getMonth().toString();
if (theDate.getMonth() < 10) {
theMonth = "0" + theMonth;
}
// convert the day from 0..31 to 00.31
var theDay = theDate.getDate().toString();
if (theDate.getDate() < 10) {
theDay = "0" + theDay;
}
// stick them all together
activeDocument.info.creationDate = theYear + theMonth + theDay;
Copy link to clipboard
Copied
I don't know what I'm doing wrong.
I literally copied and pasted your script and it didn't change the Created Date.
When I open the file in Bridge, I can see the original date, when I open the file in Photoshop and open "File Info" the Created Date in "Description" tag is still set to original date. None of the dates in "Raw Data" is changed to "2010/01/24" too.
If I intentionally define wrong string (for example '24012010') it doesn't change the Creation Date to undefined as well.
For some reason this Property behaves as it was Read-only.
Copy link to clipboard
Copied
Have you saved the file?
Copy link to clipboard
Copied
Hey DBarranca,
Yes I did. The new file has all the other properties set ok (like info.author, info.city, info.copyrighted and so on). Only the creation date remains as in original file - info.createDate just does nothing at all.
I'm not sure if SuperMerlins last answer suggests that there is a mistake in documentation?
I have CS6 documentation with the provided example and when I copy / paste the whole example the creationDate is not set.
Btw I'm on CS6 64 / Win 7
Thank you for participating.
Copy link to clipboard
Copied
@Zeeto:
"when I open the file in Photoshop and open "File Info" the Created Date in "Description" tag is still set to original date"
I think the date on the Description tab is a separate property (I believe its xmp:CreatedDate). The created date property you are accessing works - but on the created date on the Origin tab.
I'm on CS6 64 / Win 7 too and I did the following on a new tiff image:
alert(app.activeDocument.info.creationDate); // undefined (it was a new tiff image)
Going to "File>File Info>Origin", you can see the created date is empty, so clicking on the little calendar icon, choosing a date in the past and re-running the script:
alert(app.activeDocument.info.creationDate); // 20100927
So, I tried setting the value:
alert(app.activeDocument.info.creationDate); // 20100927 - its still the same as above
app.activeDocument.info.creationDate=20140105; // try to change it
alert(app.activeDocument.info.creationDate); // 20140105 - its changed
Going to "File>File Info>Origin", you can see the created date is now 05/01/2014.
alert(app.activeDocument.info.creationDate); // 20140105 - its still the same as above
app.activeDocument.info.creationDate=''; // try to clear the date
alert(app.activeDocument.info.creationDate); // undefined (as if it was a new tiff image again)
Going to "File>File Info>Origin", you can see the created date is now empty.
At no point does the date on the File>File Info>Description tab change. I think thats where the problem lies.
@Zeeto:
"when I open the file in Photoshop and open "File Info" the Created Date in "Description" tag is still set to original date"
If you want to change that value, I think you need to look at xmp:createdDate.
Thats what the script from @SuperMerlin was trying to do, change the xmp:createdDate instead of the info.creationDate property.
My understanding (some/all of this could be wrong):
For non PSD and PSD's created with versions prior to CS1 (the introduction of xmp), there is no xmp:createdDate (or xmp:modifiedDate or xmp:metaDataDate) so PS CS6 just uses the current windows created date (and modified dates) for these and displays them on the Description tab.
This can be confusing though, because windows sometimes changes the (windows) created date when moving files around. The default for WinRAR is to not store the (windows) created dates so when you unrar, it sets a new (windows) created date. Theres a lot of issues with dates under FAT vs NTFS, timezones, daylight savings, etc. For these and other reasons, I sometimes have files that have a (windows) modified date thats years before their (windows) created date, and PS CS6 just copies these dates for these files.
Just for argument sake, I just took a PS7 document, checked the (windows) created and modified dates, it was the same as what the dates were on the Description tab. I then used a date changing program which changes (windows) created and modified dates. After changing the (windows dates), the dates on the Description tab also changed.
For new PS CS6 documents (not sure of the other CS's) it creates new, real xmp:createdDate, xmp:modifiedDate and xmp:metaDataDate properties. So even if Windows changes the (windows) created or modified dates of the file, xmp knows better. xmp also stores timezone information too which overcomes a lot of my date/time issues.
Just for completions sake, I just changed the (windows) dates on a PS CS6 document but this time the dates on the description tab did not change. They are baked in
The date changing program dosnt know anything about photoshop formats either, so its not changing the internal photoshop dates, just the windows dates in the file table.
You could access the complete xmp rawdata string, then use regular expressions to chop and change the xmp:createdDate, xmp:ModifiedDate and xmp:MetaDataDate if you like but that's a whole lot of coding (it wont change the windows created and modified dates) and I'm not even sure you are still interested in this?
Edit: just realized, tiff may not store the xmp data anyway (can't check now [leaving]), so there may be nothing you can do anyway to change the date on the description tab without changing the (windows) created and modified dates. You could use the command prompt utility powershell to do this or use a application such as "Attribute Changer".