I have a lot of macros that monitor things (eg, house temperature, status of a website, etc.) and in many of those macros I write code that equates to, "Get the new value. If the value has changed from its previous value, then notify me." I do that so often that I decided it was time to make macro that does all that for me. In other words, it sets the value of a variable to a given value and then also checks to see if the value has changed, and if so, notifies me (in this case by speaking aloud, but it could also SMS me if I wanted that.) This could also be good for debugging if you are trying to find out when a variable has changed. (In that case, you could enable the breakpoint action in this macro.)
There are several techniques I used in this macro that might need explanation:
You pass the name of the variable as the first parameter and the value of the variable as the remaining parameters.
The Semaphore prevents accidental simultaneous execution from different periodically triggered macros. This is important.
This macro uses local variables to temporarily store the data it needs.
The macro uses AppleScript to assign the global variable because KM doesn't have a way to assign a variable when the name of the variable is stored in a variable. (Hint, hint.)
I have no idea how many people use KM to monitor things, so maybe I'm the only person who needs this macro.
ChangeDetect [GlobalVariable] [Value] Macro (v9.2)
ChangeDetect [GlobalVariable] [Value].kmmacros (5.9 KB)
That's not true, @Sleepy .
Have a look at this macro:
and here's the trace output:
You should be able to see that
Local_Another_Var is being set to the value of the variable pointed to by
Local_Var - which in this case is the variable
Local_Var_Indirect which contains the value "This is indirect".
I'm not saying this is any better than your solution, it's just that KM can do it.
First thing: I have no idea what your three checkpoint actions are. I couldn't find the checkpoint action in the KM editor's action list, or in KM's online documentation, or on the internet (!) I'm not sure that's important, but I had to mention it. Are you using some future, unreleased version of KM?
Second thing: I actually used the exact code that you showed me in my macro which I posted above. So I think that means you didn't understand my issue. That's not what I meant when I said, "KM doesn't have a way to assign a variable when the name of the variable is stored in a variable." What I meant was you can't do this:
Set Variable A to calculation 1
Set Variable B to string "A"
Set (variable whose name is stored in B) to calculation 2
How would I express that code in KM in three statements, and get the variable A to end up as a 2 after these statements executed?
What you showed was this:
Set Variable A to Calculation 1
Set Variable B to string "A"
Set Variable B to (contents of variable whose name is stored in B)
Your code sets B to the contents of A. My desire is to get KM to set the variable whose name is stored in the string B to be changed to some value. That's very different. And I was able to achieve that in my AppleScript code above. I'm wishing that KM had an action that did this directly.
Hi @Sleepy - I won’t be at my Mac now until Monday, so I’ll reply to you properly then.
As for Checkpoint - maybe you should search closer to home, like this forum!
Enjoy the rest of your weekend!
You're right - I got the wrong end of the stick
BTW - why did you place your AppleScript outside the IF/ELSE action? I would have expected to see it in where your Speak action is.
Just for your interest - a KM plug in I wrote a while back allows you to do what you're after like this:
The output trace being:
I didn't write the plugin in for this specific purpose!
You can find it here Set Multiple Variables Plug In Action
Hmm. You got me. Your way sounds better. My way didn't break anything.
Yes, that looks like it does what I was also doing. To be honest, my knowledge of plugins would be rated at 0 out of 100. I haven't even found where in KM's menu system I would access them. And I don't remember reading about them in the online documentation, despite the fact that I enjoy reading the online documentation. There's just so much to know, and so much fun working with what I already. know.
Nothing wrong with that as long as it does what you wish.
Plug ins are just user-written KM actions and they’re added to your macros in exactly the same way as any other KM action. You just have to install the ones you want to use and then they’re to be found in the Third Party Plug Ins section in the Actions list in the KM editor.
The great thing about them is (a) they extend the functionality of KM and (b) anyone can create them.
The Plug Ins category in the KM forum is where you can browse what’s available.
So true - we’re all learning all the time!