• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

auto date

Explorer ,
Apr 27, 2018 Apr 27, 2018

Copy link to clipboard

Copied

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!

TOPICS
Actions and scripting

Views

4.3K

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
community guidelines
Adobe
Community Expert ,
Apr 28, 2018 Apr 28, 2018

Copy link to clipboard

Copied

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

Votes

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
community guidelines
Explorer ,
Apr 30, 2018 Apr 30, 2018

Copy link to clipboard

Copied

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.

Votes

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
community guidelines
Community Expert ,
Apr 30, 2018 Apr 30, 2018

Copy link to clipboard

Copied

AG2011b143  wrote

don't see how you can make that change a text box on the page to show the current date.

It easy for a script to get the current date,  What you consider a page where your pages are that have text that needs to be changed to the current date is unknown to us.  You provided no imformation about the document you have created.

It would be very easy to write a script that get the current Date and add a text layer to your document containg the date, Some size, some font and in some position over the canvas as the top most layer.

JJMack

Votes

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
community guidelines
Explorer ,
Apr 30, 2018 Apr 30, 2018

Copy link to clipboard

Copied

it might be easy if you know how, I'm asking how 🙂

Not sure how the document is relevant, but I've attached a jpeg of it. The date would be in the bottom left corner in the box.

thanks

screengrab 2137--2018-04-30--1093 x 847.jpg

Votes

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
community guidelines
Community Expert ,
Apr 30, 2018 Apr 30, 2018

Copy link to clipboard

Copied

Your jpeg is just a flat rendering of your layered documents layers composite view. Your script would need to update or add layers to you layered document that you provide no information about. You could add a text layer containing the date over the date area in the bottom left of your jpeg if all your documents are the same size and aspect ratio and the date area is in  the same location in all documents.

The jpeg you posted is only 1093px by 847 px 15.1" by 11.8" at  print resolution of 72 DPI which I find hard to believe  is the a size you want. It would be a soft print and an image most likely to large for Web use.

JJMack

Votes

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
community guidelines
Explorer ,
Apr 30, 2018 Apr 30, 2018

Copy link to clipboard

Copied

The file I uploaded is a jpeg and I reduced the size/dpi so I could upload it here.

The original template is layered of course, and 11" w x 8.5" h at 200dpi .

I am not sure why you are being so condescending.

Votes

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
community guidelines
Community Expert ,
Apr 30, 2018 Apr 30, 2018

Copy link to clipboard

Copied

In your opinion I am being condescending IMO you did not read the forum guideline and provide pertinent information.

Guidelines & Tips for the Adobe Forums

I'm done trying to help you.

The thing is to script something you need to know what you want to do that require knowledge of things like color, font, size, document size and text location etc. Scripting is not magic

It is easy to add text layer it also possible to changes existing text layers but that layer's name need to be known and needs to be in your document.  Here is an old script of mine that time stamped the bottom left of a document.  I modified it to not include the time  just to stamp the date.

// This script was hacked by JJMack 2011

// This script is supplied as is. It is provided as freeware.

// The author accepts no liability for any problems arising from its use.

// enable double-clicking from Mac Finder or Windows Explorer

#target photoshop // this command only works in Photoshop CS2 and higher

// bring application forward for double-click events

app.bringToFront();

if (!documents.length) {alert('There are no documents open.', 'No Document');} // ensure at least one document open

else { main();}

///////////////////////////////////////////////////////////////////////////////

// main - main function

///////////////////////////////////////////////////////////////////////////////

function main() {

        /* textX and TextY positions text placement 0 and 0 Top Left corner of image in pixels */

var textX = 0;

var textY = 0;

/* Internal Photoshop Text name */

    var fontName = "ArialMT";

var fontName = "TimesNewRomanPSMT";

var fontName = "Tahoma";

/* Text Color */

textColor = new SolidColor;

textColor.rgb.red = 255;

textColor.rgb.green = 0;

textColor.rgb.blue = 0;

    // remember users Ruler and Type Units and set ours

var strtRulerUnits = app.preferences.rulerUnits;

var strtTypeUnits = app.preferences.typeUnits;

app.preferences.rulerUnits = Units.PIXELS;

  app.preferences.typeUnits = TypeUnits.PIXELS;

var docName = app.activeDocument.name;

var doc = app.activeDocument;

text_layer = doc.artLayers.add(); // Add a Layer

text_layer.name = "Time Stamp";     // Name Layer

text_layer.kind = LayerKind.TEXT; // Make Layer a Text Layer

text_layer.textItem.color = textColor; // set text layer color

text_layer.textItem.font = fontName; // set text font

text_layer.blendMode = BlendMode.NORMAL // blend mode

text_layer.textItem.fauxBold = false; // Bold

text_layer.textItem.fauxItalic = false; // Italic

text_layer.textItem.underline = UnderlineType.UNDERLINEOFF; // Underlibn

text_layer.textItem.capitalization = TextCase.NORMAL; // Case

text_layer.textItem.antiAliasMethod = AntiAlias.SHARP; // antiAlias

if (doc.width >= doc.height) {var fontSize = 24;}

else {var fontSize = 14;}

text_layer.textItem.size = fontSize; // set text font Size

text_layer.textItem.position = Array(fontSize, (doc.height - 2*fontSize )); // set text layers position in and down

try{

text_layer.textItem.contents = timeStamp();

}

catch (er) {

alert("Error Setting Contents...");

}

app.preferences.rulerUnits = strtRulerUnits;

app.preferences.typeUnits = strtTypeUnits;

}

///////////////////////////////////////////////////////////////////////////////

// END - main function

///////////////////////////////////////////////////////////////////////////////

function timeStamp(){

// Get the time and format it

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;

// Get the date and format it

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;

// create a variable with the fully formatted the time and date

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

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

MonthNames = new Array("January","February","March","April","May","June","July","August","September","October","November","December");

//todaysDate = hours + ":" + minutes + ":" + seconds + " " + amOrPm + " " + MonthNames[date.getMonth()] + " " + date.getDate() + ", " + year;

todaysDate = MonthNames[date.getMonth()] + " " + date.getDate() + ", " + year;

        return todaysDate;

}

JJMack

Votes

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
community guidelines
Guide ,
Apr 30, 2018 Apr 30, 2018

Copy link to clipboard

Copied

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();

};

Votes

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
community guidelines
Explorer ,
Apr 09, 2019 Apr 09, 2019

Copy link to clipboard

Copied

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

Votes

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
community guidelines
Guide ,
Apr 10, 2019 Apr 10, 2019

Copy link to clipboard

Copied

Something like this?

#target photoshop;

if(documents.length){

selectAllLayers();

mergeVisibleLayers();

activeDocument.activeLayer.name=$.getenv("username") + " - " + new Date().toGMTString();

}

function mergeVisibleLayers(){

try{

var d=new ActionDescriptor();

d.putBoolean(stringIDToTypeID("duplicate"), true);

executeAction(stringIDToTypeID("mergeVisible"), d, DialogModes.NO);

}catch(e){}

};

function selectAllLayers(){

try{

var d=new ActionDescriptor();

var r=new ActionReference();

r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

d.putReference(stringIDToTypeID("null"), r);

executeAction(stringIDToTypeID("selectAllLayers"), d, DialogModes.NO);

}catch(e){}

};

Votes

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
community guidelines
Explorer ,
Apr 10, 2019 Apr 10, 2019

Copy link to clipboard

Copied

Hi SuperMerlin

Thanks very much for the Script.

The Script worked like a charm the first few times, but I've had a few little issues:

On a few occasions, the script selects all layers but doesn't copy merge a top layer.

If I select a few layers, and run the script, the same happens - all layers are selected, but the copy merge doesn't take place.

I wonder whether it's an idea, to deselect all current layers first. What do you think?

A couple of times, the script has merged all, on to the existing top layer.

I really like the username option.

Is there an additional option, where we could type in a specific username, if we wanted to?

Also, I'm in the UK, but the GMT is 1 early for some reason.

Thanks again

Cheers

Steve

Votes

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
community guidelines
Guide ,
Apr 10, 2019 Apr 10, 2019

Copy link to clipboard

Copied

Is this any better?

To enter a user name run the script with the SHIFT key pressed.

#target photoshop;

if(documents.length){

selectAllLayers();

mergeVisibleLayers();

if (ScriptUI.environment.keyboardState.shiftKey){

    uName =  Window.prompt("Please enter username :- ");

    }else{

uName = $.getenv("username");

}

activeDocument.activeLayer.name=uName + " - " + new Date().toLocaleString();

}

function mergeVisibleLayers(){

try{

var d=new ActionDescriptor();

d.putBoolean(stringIDToTypeID("duplicate"), true);

executeAction(stringIDToTypeID("mergeVisible"), d, DialogModes.NO);

}catch(e){}

};

function selectAllLayers(){

try{

var d=new ActionDescriptor();

var r=new ActionReference();

r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

d.putReference(stringIDToTypeID("null"), r);

executeAction(stringIDToTypeID("selectAllLayers"), d, DialogModes.NO);

}catch(e){}

};

Votes

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
community guidelines
Community Expert ,
Aug 23, 2021 Aug 23, 2021

Copy link to clipboard

Copied

Let me move this to the Photoshop forum for you, which is a more appropriate forum for your question.


The Using the Community forum is for help in using the Adobe Support Community forums, not for help with specific programs. Product questions should be posted in the associated product community.

Votes

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
community guidelines
Community Expert ,
Aug 23, 2021 Aug 23, 2021

Copy link to clipboard

Copied

Hi, I just added the scripting tag.

Votes

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
community guidelines
Community Expert ,
Aug 23, 2021 Aug 23, 2021

Copy link to clipboard

Copied

LATEST

That script does more then rename a layer. It seem to create as new top Layer that contains a merged compostit a merge of all visible layer in the document which it renames to

"Lucky Studio Date:-23.8.21.13.26.5" or  "Lucky Studio Date:-undefined.undefined"  depend on the state of the shift key.  Is that what you want to do ins CS3?

 

The code to name a layer in CS3 would be the same coded as CC 2021. 

LayerObject.name = "String";

That script  renames the Active layer the merged layer the script created.

 

activeDocument.activeLayer.name= "Lucky Studio"+ " " +" "+ " " +" "+"Date:-" + "" + completeDate + "." + completeTime ;

 

JJMack

Votes

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
community guidelines
Guide ,
Apr 28, 2018 Apr 28, 2018

Copy link to clipboard

Copied

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();

   }

};

Votes

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
community guidelines
Explorer ,
Apr 30, 2018 Apr 30, 2018

Copy link to clipboard

Copied

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.

Votes

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
community guidelines
Explorer ,
Apr 10, 2019 Apr 10, 2019

Copy link to clipboard

Copied

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

Votes

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
community guidelines
Explorer ,
Apr 10, 2019 Apr 10, 2019

Copy link to clipboard

Copied

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

Votes

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
community guidelines
Explorer ,
Apr 10, 2019 Apr 10, 2019

Copy link to clipboard

Copied

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

Votes

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
community guidelines
Explorer ,
Apr 10, 2019 Apr 10, 2019

Copy link to clipboard

Copied

Sorry for all the replies:

When the top few layers are switched off, that's when we have issues with all the layers getting selected, and no top layer dupe merged.

If we create a new visible top layer, the script runs and the dupe merge happens to this new layer.

Votes

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
community guidelines
Explorer ,
Apr 10, 2019 Apr 10, 2019

Copy link to clipboard

Copied

A bit more info:

If the top layer is transparent, the dupe merged is placed on this transparent layer.

If the top layer has pixels, the dupe merge creates a new layer at the top.

If the top layer is hidden, (all layers get selected) the name change occurs, but no dupe merge occurs.

Cheers

Steve

Votes

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
community guidelines
Explorer ,
Apr 11, 2019 Apr 11, 2019

Copy link to clipboard

Copied

Hi SuperMerlin

Just wondering if you had a chance to look at the above?

Thanks very much

Cheers

Steve

Votes

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
community guidelines