How to automatically re-activate a deactivated palette?

After I deactivate a palette, I want it to automatically Re-activate after 10 seconds (if I did not re-activate that palette manually in those 10seconds)

To attempt this: I used a “infinite while loop” (by setting the calcalation to 1). The first action is to pauses for 10 seconds (allowing it to check once every 10 seconds). This is followed by a If clause to check if the palette is disabled or not; if it is disabled → activate the palette.

But not working!

TEST - Ractivate a macro if it has been deactivated for more than 10 seconds (for youtube Q palette).kmmacros (4.4 KB)

You should show a screenshot of your other group's settings so we can replicate your problem. Specifically, the part about how the palette is created.

Second, you should explain what you mean by "after I deactivate a palette". Do you mean closing it, or do you mean deactivating the group that generates it?

Third, do you want the palette to be displayed exactly ten seconds after you close it, or within 10 seconds? I see nothing in your current attempt that tries to determine the exact time it is closed. I'm not even sure if that's possible, unless you try to close the palette with a macro.

(Edit: Hmm, palettes close when you activate one of their items. That suggests you could record the time of the closure using a global variable that is set in each of the macros that correspond to each of the items in the palette.)

Here it is:

The palette is activated / deactivated when I press the hotkey command + Q (as shown in the screenshot above). But I also have a macro within this macro group that deactivates this macro group (see screenshot below) when I press ;. By “after I deactivate a palette“ I mean either means of deactivating the macro group (command + Q or ;)

I would like the palette to be displayed (re-activated) exactly 10 seconds after I close (deactivated) it by command + Q or ;

I could be totally wrong but I thought that the “infinite while loop” would keep monitoring if the palette is disabled or not every 10 seconds (And if not it will supposedly activate the palette), so there’s no need to determine the exact time it is closed?

Here’s why I set it up like this (maybe there’s a better way):

This palette is used only when I’m on YouTube in Google Chrome. All of the macros (will) use “single letter“ or “Shift+letter“ trigger, which intefere with normal keystroke when typing at the search bar. Therefore, I have one macro (mentioned above) that take me to the search bar (using JS code) then deactivate the palette (macro groups) so that I can type as normal.

Usually, it takes less than 10 seconds for me to type something at the search bar, therefore I want the palette to reappear (re-activated) on its own after those 10 seconds so I can used the macros within them again without pressing command + Q to activate the palette.

Deactivate Palette.kmmacros (3.3 KB)

Intermittent monitoring every ten seconds will not ensure that the palette will be reopened exactly ten seconds after it was closed. In order to detect a precise gap of ten seconds, you actually have to know when the 10 seconds starts. Otherwise a ten second interval could occur a mere 5 seconds into the window.

Irrespective of this issue, I choose to avoid Chrome, so I won't be able to advance this issue for you.

But I recommend that you consider my words above, when I said, "you could record the time of the closure using a global variable that is set in each of the macros that correspond to each of the items in the palette."

1 Like

Oh right! How did I not realized that!

YES! This works!! Thank you so much! this is another one of those thing I was hoping to be able to do forever!

I'm glad you solved it. However I'm looking at your code and I don't understand how it does what you want. For one thing, you aren't actually examining the value of the Close_Time variable. If the macro works, then ignore what I'm saying here, but I think you need to modify your TEST macro to trigger every one second, check if the value of TIME()-Close_Time>10, and if so, activate the macro AND reset the value of Close_Time. In addition, there appears to be a minor bug that the TEST macro could fail if Close_Time is empty (there are a few ways to fix that.)

As always, there's a 10% chance that I'm wrong.

1 Like

It doesn’t!:joy: I know why I think it works now haha, because I was deactivating the palette at exactly 10/20/30/40/50/60 seconds of each minute when I was testing it out!

Yup Yup added that! Now it ‘actually' works.

Umm..sorry for asking stupid question again, but why do I need to reset the value? It works fine without having to reset Close_Time right now (I think).

What I have now:

And by reset, do you mean like this:

Sorry I don’t really understand what you mean by “Close_Time is empty”? Could you elaborate a little pls?:smiling_face_with_tear:

I understand that TIME() - Close_Time > 10 means "Has more than 10 seconds passed since the time stored in Close_Time?"

All KM variables can be considered empty (and will evaluate as being empty) until they are assigned a value. Once you assign a value to a global variable (eg, Close_Time), it is no longer empty. But if you try to evaluate an expression (eg, TIME()-Close_Time>10) prior to assigning the variable Close_Time a value, you may not get a correct result. Since I like my macros to be robust, I don't assume that a variable contains a value.

Yes, that's what I meant.

Because if you don't reset the value to TIME(), then the expression TIME()-Close_Time will always be greater than 10.

Using timers in this way is something I do every day.

1 Like

OK I understand now. Thank you!