Welcome to episode 26 of the Free Function Friday series. This week’s function will get us the current time in a manageable way. Normally when calling the Date() method you have to follow up with the getHours, getMinutes, and the getSeconds methods. These methods all return data in a way that we may not normally use in day to day tasks. Hours for example starts at 0 then increments to 24. Minutes and seconds will have single digit numbers for 1-9 instead of 01, 02, 03, and so forth. Most digital clocks use the format like this,
2:34 PM. Some computer setups include the seconds as well like this,
2:34:05 PM. What we build in this function will allow us to customize the separator and choose wether or not to include the AM/PM suffix. Why is this a helpful function you ask? I’ve used this very function when exporting data from a project into a text doc and I would use a time suffix for the name of the document to help keep things organized. So if I was just exporting out a list of say, installed effects during an install cycle, I would be using a file name like “myEffects.txt”, but then add the current time to then prevent myself from accidentally overwriting the file as I exported the doc throughout the install process. My file names would show as “myEffects_2_34_05.txt”, “myEffects_2_50_29.txt”, “myEffects_3_26_12.txt”. Setting the separator to “_” helped in making a string that was compatible with file name structures. Another example is just needing to place the time a process was last run in your script UI for the user to have feedback. Say they clicked a button in your UI to organize the project, you could have a bit of text that says “Project was last organized at 2:34:05 PM” posted in your UI. Hopefully that gives you a few ideas.
If you haven’t done so already there is a Free Function Friday introduction video located here that has some important information pointing to a few resources that will come in handy when scripting for After Effects.
Episode 26 currentTime:
Legal note: The Adobe ExtendScript code talked about in this article and accompanying embedded video(s), and/or graphic images are not guaranteed to be compatible with every version of After Effects. David Torno, ProVideo Coalition, and Moviola will not be held liable for any misuse or incorrect use of the provided ExtendScript code. Use at your own risk.
All of the code I provide in this series, has been created and tested in After Effects CC 2014. Unless otherwise specified in the episode, the code should be compatible with After Effects CS6 through CC 2015. I’ve done my best to avoid depreciated code (code that Adobe removed at some point), and made these functions as compatible as possible. There will however be the occasional piece of code that is brand new as of a certain version of After Effects and therefore will not be backwards compatible from that version. I will mention these if that is the case.
With that said, all the code I provide in this series is open source and free to use in your scripts. I highly encourage you to expand and improve upon the code I provide and start making your own custom functions as well, but please do not repost the code I show in this series as is and claim it as your own. If you use any of the code provided in this series please give credit where credit is due. This series is meant to provide, what I feel is useful code, as well as to hopefully further explain ExtendScript and it’s quirks. While the functions we build throughout this series can perform a task all on their own, they are not meant to be a solo script. How you combine them together and expand upon them is when you will gain the most from these functions.