The brief description of @set in the release thread has me wondering if it can be used to create a toggle button that will run one of external two commands depending on the value of a variable set by clicking the button?
Specifically, I use NirCMD to switch between speakers and HDMI as my active audio device using two different commands set to global hotkeys. Can I now put these two commands into a toggle button and use a variable to help DOpus "remember" the state of the button? In other words, I hope to be able to click once to run one command and toggle the button ON, then click again to run the second command and toggle the button OFF.
Yes, that type of thing is one of the problems the new persistent variables aim to solve.
You may also be able to make a script which queries the current default audio device so that you don't have to use the variable at all (and then the variable will never be out of sync with reality, like would happen if something else changed the audio device). I'm not sure though. WMI has some ways to query audio devices, and can be accessed via scripts, but I don't know if it lets you tell which device is the current default. Might be worth looking into though, if you're OK with a bit of scripting.
Here's how to do the toggle, with the variable being saved between reboots:
(I've called the variable HDMIAudio.)
@ifset:$glob!:HDMIAudio
@set glob!:HDMIAudio
<put one of your NirCMD commands here>
@ifset:else
@set glob!:HDMIAudio=1
<put your other NirCMD command here>
I found I can indicate its state by also toggling sounds. Since I don't use them, I will never notice if they're on or off. Adding this code to my button does the trick!
Set SOUNDS=Toggle
It's a bit of a hack of course, and if I need to do something similar to another button I'll have to find another setting that I don't use. But I have a feeling that you guys are working on this problem, so I'm not worried
Leo, I'm confused about the syntax in your example. It looks a bit different from the manual, where you can test a value, for instance @ifset:DUAL=on, but not just @ifset:DUAL
Line 1: @ifset:$glob!:HDMIAudio
Are you just testing if $glob!:HDMIAudio exists? (Regardless of value?)
Or testing if it exists AND is set to 1?
Line 2: @set glob!:HDMIAudio
What does this do to the variable?
In contract , below you set it to 1: @set glob!:HDMIAudio=1
The @ifset directive can now test if a variable has previously been set by the @set directive (although it can't actually test what the value is - only if it exists or not). For example, @ifset:$glob:foo would test if a global variable called foo had been set.
@set glob!:HDMIAudio removes the variable entirely. (If it did anything else, the @ifset stuff in my example wouldn't have worked, since @ifset can only test if a variable exists or not and cannot test what the variable's value is. So we need a way to create the variable (with some value; it doesn't matter what but 1 is used in my example) and another way to destroy the variable.)
I saw the notes in the new beta and meant to try it. I don't feel like restarting my system right now, but I'll install the new version soon and try it out