So at work, I use a program that requires a lot of text fields to be filled in, I have several macros that use AppleScript to help me select the fields, get the value of the fields so they can be copied, set the fields to certain text, etc. But something that bothers me, is that all the macros are basically the same, i.e. They start with an action (set, get, click, press) and then they have a really long string that references the element the action is being performed on, like this:
set emailOnFile to value of static text 1 of group 2 of group 9 of group 3 of group 10 of group 1 of UI element 1 of scroll area 1 of splitter group 1 of window 1
The problem with this is first off, that long string is impossible to know what it refers to without comments or something to identify it, and second it really reduces the readability of the script itself.
What I would like to do, is to be able to set the element reference (the long string) to a variable and then use the variable to reference it. Something like this:
set ref__emailOnFile to "static text 1 of group 2 of group 9 of group 3 of group 10 of group 1 of UI element 1 of scroll area 1 of splitter group 1 of window 1"
So that way the first script could be written like this (which is much more understandable and I actually know what it’s referring to):
set emailOnFile to value of ref__emailOnFile
But when trying that, it gets an error:
Can’t get value of "static text 1 of group 2 of group 9 of group 3 of group 10 of group 1 of UI element 1 of scroll area 1 of splitter group 1 of window 1".
Now I’m pretty sure the reason for this error is because it is treating the variable as a string rather than a reference to the location of the element, but I just can’t seem to find a way to make this work as I would like. It seems fairly straightforward but I’m hitting a wall here, if it’s not possible then no big deal, I just figured I’d see what you guys had to say.
Thanks for any advice!
- Kevin