Hi there
This came up before I think: is it possible to give in the value of the date?
Right now, I use KM for this but SF can do as well I guess.
I always start every filename with the date (yymmdd).
Right now I'll type 3 times 'd' and it's replaced by the date.
So that's for the 2the request: can a key or wordstring be a trigger for a macro?... That's very powerfull because I'm running out of key-combinations to remember ;-)
- Christian Scheuer @chrscheuer2019-10-04 08:16:24.224Z
@NickLeyers + @Nick_Leyers (just in case hehe),
thanks for asking.
Yes Javascript is pretty good at handling date related stuff. To get it out as yymmdd, you'll have to do something like this:
function yymmdd() { var now = new Date(); return now.getFullYear().toString().slice(-2) + ('0' + (now.getMonth() + 1).toString()).slice(-2) + ('0' + now.getDate().toString()).slice(-2); } log(yymmdd());
Christian Scheuer @chrscheuer2019-10-04 08:17:22.288Z
I moved this to the How to section (for the part about dates) - the request for key sequences I believe we've already registered (at least I remember it and we do think about it from time to time).
- In reply tochrscheuer⬆:NN Leyers @NickLeyers_old_acc
Nice, thanks.
If I use this at the end (witout the log)
sf.keyboard.press({ keys: (yymmdd()) });
Than I get 'a' as result. Is there a better way?Christian Scheuer @chrscheuer2019-10-07 08:59:16.551Z
Yes you need the sf.keyboard.type to type a string of characters. press is for special keys :)
Christian Scheuer @chrscheuer2019-10-07 09:00:06.975Z
- In reply toNickLeyers_old_acc⬆:AlexanderW @AlexanderW
I'd like to jump in here,
i have tried to extract a function from the above that inserts the current date in the format YYYYMMDD at the current cursor position, as this would be helpful when naming delivery files. Alternatively also date and time would be great.
What I haven't got yet is that the date is 'typed in' to the naming field.Best,
Alex- NN Leyers @NickLeyers_old_acc
If you use the sf.keyboard.type, the date is 'typed'?
AlexanderW @AlexanderW
Thank you Nick for asking. I am not very experienced with scripting.
After reading this thread I have tried the following, but it threw an error message:
function yyyymmdd() {
var now = new Date();
return now.getFullYear().toString().slice(-0) +
('0' + (now.getMonth() + 1).toString()).slice(-2) +
('0' + now.getDate().toString()).slice(-2);
}log(yyyymmdd());
sf.keyboard.type({ keys: (yyyymmdd()) });Kitch Membery @Kitch2020-09-15 19:24:36.665Z
Hi AlexanderW!,
function yyyymmdd() { var now = new Date(); return now.getFullYear().toString().slice() + ('0' + (now.getMonth() + 1).toString()).slice(-2) + ('0' + now.getDate().toString()).slice(-2); } const todaysDate = yyyymmdd(); sf.keyboard.type({ text: todaysDate, })
This should do it :-)
AlexanderW @AlexanderW
Hi Kitch,
awesome, that did the trick. Thank you for helping out.
It's also great that I learn a little bit at every step just by looking at the scripts.Cheers,
AlexKitch Membery @Kitch2020-09-15 21:37:22.212Z
You’re totally welcome:-)
- In reply toKitch⬆:GGabriel Lundh @Gabriel_Lundh
Hi master Kitch!
I am trying my best to rearrange the output of todaysDate. I have a structure that I have to follow for a job which is MMDDYY. So I tried to arrange it:
function mmddyy() { var now = new Date(); return now.getMonth() +1).toString()).slice(-2) + ('0' + (now.getDate().toString()).slice(-2) + ('0' + now.getFullYear().toString()).slice(-2); }
But for some reason this throws the script of... How should I go about doing this?
You rock!
All the best,
GabrielKitch Membery @Kitch2021-09-03 07:57:59.810Z
This should do the trick :-)
function mmddyy() { const now = new Date(); const yy = now.getFullYear().toString().slice(-2); const mm = ('0' + (now.getMonth() + 1).toString()).slice(-2); const dd = ('0' + now.getDate().toString()).slice(-2); return mm+dd+yy; } const todaysDate = mmddyy(); log(todaysDate);
Rock on!
- GGabriel Lundh @Gabriel_Lundh
Its hard to show how much I appreciate these quick and perfect turnarounds!
Thank you so much, You rule Kitch!!Kitch Membery @Kitch2021-09-03 08:17:45.332Z
You're totally welcome mate! :-)
Rock on!
- In reply toKitch⬆:JJosh Reinhardt @Josh_Reinhardt
I'm wanting to use this script to enter the date text into a track name. I'd like to add this as an action in a macro so it types the current date followed by other actions. How can this be done? Thanks in advance.
Kitch Membery @Kitch2024-01-30 18:23:39.058Z
Hi @Josh_Reinhardt,
To do that, create a script and give it a name like "Date Stamp".
Add the following code to the script.
function mmddyy() { const now = new Date(); const yy = now.getFullYear().toString().slice(-2); const mm = ('0' + (now.getMonth() + 1).toString()).slice(-2); const dd = ('0' + now.getDate().toString()).slice(-2); return mm + dd + yy; } const todaysDate = mmddyy(); sf.keyboard.type({ text: todaysDate });
You can then create a new macro and add the "Date Stamp" script as an action using the "Add Action button" to the macro, followed by other actions.
- In reply toAlexanderW⬆:
Kitch Membery @Kitch2020-09-15 19:27:56.706Z
Oh and btw... You are probably wondering how to format your code in the forum.
To format the code surround it with 3 backticks on their own line (one line of 3 backticks before the code, one line of 3 backticks after the code) - ```
Rock on!