“Find Image on Screen” returns a variable that is a Structure - it has multiple properties like .x and .y, etc. Is it possible for me to create my own structures?
If not, is there a recommended way to pass more than one parameter when I use the “Execute a Macro” action?
Variables are simply strings. Always. Plain text strings and nothing more.
Keyboard Maestro has to deal with things like points and rectangles and so Keyboard Maestro allows a string that consists of a sequence of numbers separated by commas to be considered points or rectangles as appropriate.
Variables in that format can be referenced as arrays, as in “Var[3]”. So if Var holds “10,20,30,40”, Var[3] would be 30.
To simplify the use of rectangles and points, there is also a dot notation where you can use Var.top which is exactly equivalent to Var[3]. The possible values are:
x (1)
y (2)
left (1)
top (2)
width (3 or 1 - depending on whether there are 2 or 4 elements in the array)
height (4 or 2)
right (Var.left + Var.width)
bottom (Var.top + Var.height)
MidX (Var.left + Var.width / 2)
MidY (Var.top + Var. height / 2)
fuzz (5)
But they are all internally defined, you cannot define your own.
To pass more than one parameter, pick a character (or string if necessary) that is not used in your text and concatenate them that way.
Comma’s obviously work for some simple cases. If you text needs comma’s in it, then perhaps bullets (Option-8 •). Failing that, you can use some unique string like “,KMSEP,”. Use the Search Variable acton to break the parameter apart.
Or alternatively, just define the input variables. All variables are global. And yes, in programming, global variables are generally bad and all that, but we’re not building operating systems here.
“we’re not building operating systems here” LOL!!! Thank God! And no peer reviews either. Whew!
So, just to clarify, if I do use commas, then I can use the “Var[3]” method. I’d only need to break them apart using some other method if I didn’t use commas. Right?
FWIW, for the purposes of KM, I don’t mind global variables. Just looking for the best way to do things.
That’s actually quite an interesting idea. I may not use it for parameters (then again, I might), but there’s something else I’m doing for which it would be perfect!