How to set date format as plain text inside Set Variable?

When I use the Set Variable, I would like to have this text used as plain text:
%ICUDateTime%yyyy-MM-d, hh.mm.ss a%

Right now when I run this macro, it automatically converts it to the current date as seen below:
Screen Shot 2022-05-12 at 10.48.32 PM

I would like to use this variable globally, but the way it is now, it always gets stuck with the date of when I ran the macro. How to make %ICUDateTime%yyyy-MM-d, hh.mm.ss a% be seen as just plain text? I tried using single and double quotes, but that doesn't change it.

Hope it makes sense what I'm trying to achieve...

Click on the "gear" icon in the action and check the "Process Nothing" item; this will stop KM interpreting the text that you're setting the variable to.

1 Like

Thanks. That helped me learn a new thing at least :slight_smile:

What I'm trying to achieve is different and maybe my question wasn't very clear.
Maybe you can help me solve it?

What I want is to set a variable that is plain text:
%ICUDateTime%yyyy-MM-d, hh.mm.ss a%

Then when I use the New Folder action, I use this:
BetterTouchTool Backup, %Variable%currentDate%
So I can end up with this:
BetterTouchTool Backup, 2022-05-12, 11.17.24 PM

You know what I mean?

With the Process Nothing option, it just prints the variable after the name like this:
BetterTouchTool Backup, %Variable%currentDate%

No, you're not being clear.

Tell me, what's wrong with doing this?

which creates a folder called

Test,2022-05-12, 11.23.18 pm

in my Downloads folder. Obviously tweak it to suit you.

1 Like

I want to create a variable that I can use with other macros so I don't have to type that date format over and over again, so if I set the variable currentTime, for example, then I just need to use that whenever I want to use the current time when creating new folder actions.

Or for example, if I decide to change the format, I just need to change the variable, not all actions across multiple macros

%ICUDateTime% is a token that always returns the current date and time. That's what it's for. It's not a function that takes a given date and formats it.

There are a handful of similar DateTime tokens discussed in the wiki. Maybe you want %ICUDateTimeFor%.

But if you want a variable that holds a specific date in a particular text format, why don't you just set a variable to that text?

2 Likes

This is the format I want to use, which is not available as a "default" format:
2022-05-12, 11.17.24 PM
When using certain formats, they use : and that it not allowed when creating folders or files, that's why I use a dot to separate the hour, minute, second.

That's what I tried initially and what made me start this thread. It's not working, because when I run the action it doesn't use the current date, it uses the date of the last time I ran the variable. Meaning, I can run it once, but the second time I run it, it doesn't do anything, because it's trying to create a folder with the exact same name as the one I created first.

Here are the 2 macros, maybe you guys can see what's wrong:

OK, now I see. You want the current time in a particular format, but you don't want to have to keep entering that format in every macro you make.

My suggestion is to make a subroutine like this:

Whenever you want the current date in that format in another macro, you execute the subroutine and save it to a variable that you use however you want.

Options:

  • Put this in your Create Folder action:
/Users/dannywyatt/Desktop/BetterTouchToo! Backup, %ICUDateTime%yyyy-MM-d, hh.mm.ss a%
  • Save this as a Favourite action and call it up when needed.

@drdrang I considered calling a separate macro but loading a Favourite is quicker if you use the hotkey.

But the goal of a variable is that you can change it and it will change the value everywhere. As much as a favorite action could make things easier, it doesn't allow future updates while updating every macro where the action is. Unless I'm missing something, because I've never used favorites.

When the Set Variable to Text action is set to process text, it sets the variable currentDate to the data that the '%ICUDateTime%` token represents at run-time:

"2022-05-13, 02.09.22 am"

When it is set to "Process Nothing", it sets currentDate to the literal string:

"%ICUDateTime%yyyy-MM-d, hh.mm.ss a%"

The Create New Folder action specifies a path at which to create a folder. Whatever currentDate is set as will make up part of that path, and that will either be the time captured when the variable was set or the literal string.

Good point. Another speedy way to enter the token would be to make a macro that inserts the text

%ICUDateTime%yyyy-MM-d hh.mm.ss a%

with a short typed string trigger. That would give you direct entry of the token when making new macros and avoid variables entirely.

1 Like

That's a good idea too! So something like this...

Date & Time.kmmacros (21 KB)

Macro screenshot

Exactly. The Value will change everywhere.

But you are asking for a Variable that is created by a maths, formula, token and want that “formula” to automatically change everywhere and to recalculate a new Value rather than use the original value that the formula arrived at, when the variable was created.

There is no mechanism for that (other than trying to break the formula down into every single mathematical element and number and making variables for each).

That could work for 1 + 2 where 1 and 2 are replaced by variables. But even in that case you would not be able to make “+” into a Variable directly. You would need to have a separate routine that looks to see if a Variable was say “+” or “-“ and applies the appropriate maths.

This would be completely impractical for your Date example and would anyway be too much work to make and too complex to use.

So, the answer to your question is, no you can’t do what you are asking.

2 Likes

But isn't this the exact same process when creating a variable? A variable sets a text and then when you call that variable, it uses that text.
I understand that we can have 2 formats:
1 - The variable gets assigned the date of when it was ran (Process Text Normally)
2 - The variable gets assigned a string/text (Process Nothing)

So in my mind, using the second option would be the right way to do it.
The issue here is that the New Folder action is not processing
%ICUDateTime%yyyy-MM-d hh.mm.ss a% properly (in my opinion).

It should use the text based on the variable and then the action itself would interpret that as a variable and replace %ICUDateTime%yyyy-MM-d hh.mm.ss a% with the actual date. Pretty much the same when we manually type/paste %ICUDateTime%yyyy-MM-d hh.mm.ss a% into the field.

I think we could have an option to set this as a string, for example, if instead of
Text Here - %Variable%VarName% (which would result, for example, in Text Here - The Sun is Shinning)
we used
Text Here - "%Variable%VarName%" (look at the quotes)
then we would have the folder/file name as
Text Here - %Variable%VarName%

Does it make sense?

@drdrang and @noisneil, what you guys are missing here, is that the goal is to use a variable that can easily be changed and used. The issue is not (only) that I need to remember this long string. yes, it helps, but I don't want to paste something that if needs to be changed in the future, then I have to go and open each macro, then each action, and change it. Let's say that one day I decide that instead of
2022-05-12, 11.17.24 PM
I want this
2022---05---12 - 11-17-24 PM
?

With a variable I just need to change it in one place.

The only way I found that this works (but I wanted to avoid that extra action) is to include an Execute Macro action before the New Folder action. This will execute the Variable macro (if it's set to Process Text) and update it to the current date. Will this be super accurate when it comes to the date, by the second or millisecond? Probably not, but in this particular case, not relevant. It gives me a pretty accurate date, different enough to create a new folder right away and end up with a new current date.

But yeah, my goal was to have variables work as they should (or what I think is the right way this should work) :slight_smile:

Not sure I totally understand what you mean...
From what I'm reading, you are probably misunderstanding what I mean, maybe because I'm using the wrong wording?

When you use the Create Folder action and you type for example:
New Folder Name - %ICUDateTime%yyyy-MM-d, hh.mm.ss a%
the Create Folder action itself will interpret this as
New Folder Name - 2022-05-12, 11.17.24 PM
right? And that's the name of the folder

Now when I'm using a variable currentDate that has this value assigned
%ICUDateTime%yyyy-MM-d, hh.mm.ss a%
(maybe this is what is causing the issue, that I use the word "value"?)
the end result should be exactly the same as when I manually type
New Folder Name - %ICUDateTime%yyyy-MM-d, hh.mm.ss a%

So typing
New Folder Name - %Variable%currentDate%
should be, at least in theory, the same as manually typing
New Folder Name - %ICUDateTime%yyyy-MM-d, hh.mm.ss a%
because that's what a variable is for.

I understand that we could set the variable "type" when using the Process Text vs Process Nothing, but to me Process Nothing should just use plain text and then the New Folder action would create the conversion between currentDate and the %ICUDateTime%yyyy-MM-d, hh.mm.ss a% "code" (or whatever that's proper name that thing has...)

Is it making sense what I'm trying to explain?
Are we talking about the same end result and same workflow? Let me know :slight_smile:

But when you set the variable to Process Nothing, it stops being a math, formula, token, and it becomes plain text, right? At least that's what I'm getting from that. That being said, when the variable becomes plain text, the New Folder action should interpret that as plain text so when using %Variable%currentDate%, the action should interpret this:
New Folder Name - %Variable%currentDate%
as this
New Folder Name - %ICUDateTime%yyyy-MM-d, hh.mm.ss a%

so when it processes that information, the end result should be:
New Folder Name - 2022-05-12, 11.17.24 PM

Right now, when set to Process Nothing it ends up creating a folder with this name:
New Folder Name - %ICUDateTime%yyyy-MM-d, hh.mm.ss a%
literally! :confused:

Yes, absolutely. But this cannot be done in the current implementation of Keyboard Maestro. What you are asking for is a new feature.