Is there any simple script which gives current date to a specific text layer every time I open this project?
Thank you for your time!!!
Copy link to clipboard
»a specific text layer«
How is the Layer identified?
By it's name, "Date"!!! If you mean that.
Beg your pardon, let me see if I understand: you are looking for a script that automatically updates the name of a text layer, showing the current date or a specific date every time you open the file in photoshop? This script would allow you to automate name to date only for text layers?
May i ask what are the benefits of this solution and why text layers only?
Given that I really understood your request.
I am looking for a script which will update the text of a text layer, not the name of it. For example, let's say I have a text layer into my project with the name "Date" and it's text is "28/05/2021". What I want to do with this script is to update this text to current date automatically or by click on a button, no problem. Just to avoid looking for this text layer and doing it by the hand.
Copy link to clipboard
evnt = 'layersFiltered'; if (name.split('Photoshop').length - 1 && !$.getenv('not')) $.setenv('not', 1), notifiers.add(evnt, File($.fileName)) else if(typeIDToStringID(arguments) == evnt && (aD = activeDocument).name == 'Project.psd' && (tI = aD.artLayers.getByName('Date').textItem) .contents != $.getenv('Date')) $.setenv('Date', tI.contents = new Date().toLocaleString())
Save above script to: C:\Program Files (x86)\Common Files\Adobe\Startup Scripts CC\Adobe Photoshop
Then relaunch Photoshop, and remember it works only for document named 'Project.psd' until you change its name in the code. The text layer named 'Date' should not be in any layer set, but directly in document at any position. btw I used date with time to let script detect your project not once a day, but any time of any day.
This script will be called every time when calling any script, including internal scripts such as ruler -> "straighten button". Why is this necessary?
Clicking 'straighten button' does not produce 'layersFiltered' event for me, however that event may occur by doing other stuff of course, but it must fulfil given condition, and once changed date does not change until you relunch Photoshop.
I was talking about the script above and not the event.
I'm sorry, now I'm confused. I completely don't know what you ask for then.
Maybe you mean script will be triggered any time you do something in photoshop (or anything that produces whatever event?). I checked that and it does not work like it. The StartupScripts are loaded only once, at time of launching Photoshop. Later they are inactive until you make they can be called. Or there is something you discovered you'd like to share?
The StartupScripts are loaded only once, at time of launching Photoshop.
All StartupScripts are executed each time before any script is called. You can check by inserting an alert there.
Ah right, that's true, I noticed it by opening Scripts Event Manager. But to avoid consequences of unedeed actions there're events that let you filter how exactly you want to use startupscript.
I didn't think about it.
It seems to me that the author just wanted a simple script (not necessarily automatic) that did the job for him.
It seems he wants a script that let him to forget of doing the same thing manually each time he starts project. Later he precised he wants it happens automatically or if not possible, by triggering it, so to be half-automatic. He marked my code as correct. Who unmarked it? 😕
Copy link to clipboard
This is what I came up with from hacking away at some other code:
EDIT 29th May 2021: v1.2 – I like the suggestion of adding a timestamp from Kukurykus, so I have edited/updated the original code.
EDIT 30th May 2021: v1.3 – I have now added a conditional check that the filename is "Project" (without the quotes, case sensitive) in addition to the previous requirement that the layer name is "Date" (again, borrowing the idea from Kukurykus).
Sorry, I forgot to mention that I would use File > Scripts > Scripts Events Manager... to automatically trigger this script to run on the open document event. I would probably use a "safer" unique layer name than the generic "Date" though, just in case this was accidentally triggered by a file that contained the layer name "Date" that was not meant to be updated.
EDIT 30th May 2021: I have added a second conditional safety check so that both the filename and layer name have to be matched before the script executes.