1

I'm trying to create a date variable for a production template in Photoshop so that it updates to the current date when I save a new version of the document. It doesn't seem like much but over time it could save a ton of clicking and typing. Any ideas? I know you can do this in InDesign but unfortunately our studio doesn't spring for that.

  • not sure about variable but it'll whole lot easy with script, – Mr.Online Sep 17 at 2:57
3

To my knowledge there're no date variables in Photoshop but this can be solved using a simple script and Photoshop Events Manager system which allows to run Actions or Scripts after a particular event was fired in PS.

For instance, in a document I have a bunch of layers and a text layer called _dateTextItem:

enter image description here

And I have this script saved anywhere on a computer as a .jsx file: setDate.jsx:

/**
 * @description this function will change the contents of a text layer _dateTextItem to current date and time
 */
(function(){

    var dateLayer;

    try
    {
        dateLayer = activeDocument.layers.getByName("_dateTextItem");
    }
    catch (e)
    {
        // if no _dateTextItem layer found, aborting
        return;
    }

    var newDate = new Date();
    var yyyy = newDate.getFullYear();
    var mm = newDate.getMonth() + 1;
    var dd = newDate.getDate();
    var hh = newDate.getHours();
    var min = newDate.getMinutes();
    var sec = newDate.getSeconds();
    var milliseconds = newDate.getMilliseconds();

    // the format will be YYYY/MM/DD — HH:Min:Sec, change to your preferred version
    dateLayer.textItem.contents = yyyy + "/" + zeroPad(mm) + "/" + zeroPad(dd) + " — " + zeroPad(hh) + ":" + zeroPad(min) + ":" + zeroPad(sec);

    function zeroPad(value)
    {
        if (String(value).length == 1) return "0" + String(value);
        return value;
    }
})();

The script will look for a _dateTextItem layer and change it contents to a date. If no layer is found, the script will ignore the document.

Now, in Photoshop File > Scripts > Script Event Manager... window..

  1. I select an event (Save Document);
  2. Chose a script (Browse.. and navigate to my .jsx file);
  3. Add the listener to the list;
  4. And done.

enter image description here

And now if I save my document, the content of the _dateTextItem will change to the date, specified in the script:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.