Skip to main content
Inspiring
April 27, 2018
Question

auto date

  • April 27, 2018
  • 3 replies
  • 6243 views

I'm trying to automate the proof sheets we produce as much as possible - I've managed to simplify repetitions using smart objects, but would like to add the date that the file is opened as text .

Is this possible? If so, can someone show a scripting newbie how? I've done more complex stuff in Acrobat, but our proof sheets need to be created in photoshop as they all contain very different/custom content that uses images/technical drawings, measurements, etc.

thanks in advance!

This topic has been closed for replies.

3 replies

Known Participant
April 10, 2019

Great stuff. Works silky smooth on a pc.

The Script runs on a mac, but get the following error:

Cannot execute script in target engine 'main'!

(#1116) Can't start debug session.

The script runs but the name is replace by 'null', which I guess could be a username issue?

Am on Photoshop 2019 on mac and 2018 on pc if that helps.

Cheers

Steve

Known Participant
April 10, 2019

Just for your info.

The script seems to work most of the time, but still having a few issues:

On one file a text layer is created with the correct info, but no dupe merge is carried out.

Have had a few runs of the script where all layers are selected, without the dupe merge.

And a couple of instances where the merge gets copied on to the existing top layer.

Thanks again.

Steve

Known Participant
April 10, 2019

As a second option, would it be possible to give us just the renaming part of the script?

Then we could create the dupe merge in an Action, and sit the renaming Script at the end of the Action?

Cheers

Steve

SuperMerlin
Inspiring
April 28, 2018

Photoshop layers are time stamped when they are updated. Would this do what you want?

$.writeln(getLayerChangedDate());

function getLayerChangedDate(){

   var ref = new ActionReference();

   ref.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "metadata" ) );

   ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID("Ordn" ), charIDToTypeID("Trgt") );

   var desc = executeActionGet( ref );

   if ( desc.hasKey( stringIDToTypeID( "metadata" ) ) ){

      var descMetadata = desc.getObjectValue( stringIDToTypeID("metadata" ));

      var timeInSeconds = descMetadata.getDouble( stringIDToTypeID("layerTime") );

      var d = new Date();

      d.setTime( timeInSeconds * 1000.0 );

      return d.toLocaleString();

   }

};

Inspiring
April 30, 2018

thanks -  I see how you can add a script via file>scripts>browse but don't see how you can make that change a text box on the page to show the current date. can you advise? I've never used scripts in photoshop before.

JJMack
Community Expert
Community Expert
April 28, 2018

If you have scripted your proof sheets using Photoshop scripting  where you create a composite layered document that containing your images as smart object layers there should be no problem adding additional script code to expand the documents canvas and add a text layer to add  a date in the added canvas area and also save the PSD with a filename that includes the date. If ilu just need to tile out your images  You could look into Contact Sheet II it Photoshop presets scripts folder.

JJMack
Inspiring
April 30, 2018

thanks, the contact sheet won't do what I need though.  I have everything organized except the auto date. I have no idea how to do that. I've never scripted in photoshop before, I've figured out how to add a script, but not to just the current file, I see how you can add a script via file>scripts>browse but don't see how you can make that change a text box on the page to show the current date.

Known Participant
April 9, 2019

The easy way would be to fill in the Date field with any date and name this TEXT layer as "Date Field" (no quotes) then when the document is opened you could run the script to place todays date in that position.

#target photoshop;

if(documents.length) main();

function main(){

try{

activeDocument.activeLayer = activeDocument.artLayers.getByName("Date Field");

if(activeDocument.activeLayer.kind != LayerKind.TEXT){

    alert("This is not a text layer!");

    return;

    }

activeDocument.activeLayer.textItem.contents = dateToday();

}catch(e){alert("Date Field layer does not exist");}

};

function dateToday(){

var date = new Date();

    var d  = date.getDate();

    var day = (d < 10) ? '0' + d : d;

    var m = date.getMonth() + 1;

    var month = (m < 10) ? '0' + m : m;

    var yy = date.getYear();

    var year = (yy < 1000) ? yy + 1900 : yy;

    var digital = new Date();

    var hours = digital.getHours();

    var minutes = digital.getMinutes();

    var seconds = digital.getSeconds();

    var amOrPm = "AM";

    if (hours > 11) amOrPm = "PM";

    if (hours > 12) hours = hours - 12;

    if (hours == 0) hours = 12;

    if (minutes <= 9) minutes = "0" + minutes;

    if (seconds <= 9) seconds = "0" + seconds;

    todaysDate = day + "-" + month + "-" + year + " " + hours + ":" + minutes + amOrPm;

    return todaysDate.toString();

};


Hi SuperMerlin

Great Date script, cheers..

I’m wondering if you can help me.

I want to create an action, including script, for the following:

Create a duplicate merge layer (of all visible layers in photoshop)

Then add the user name (could be the login name) and date to this merged top layer

Thanks very much