Is there a way to set the visible property of some arbitrary static text? I have a series of text fields that I want to make visible or invisible depending on certain conditions. They’re named “_rule01”, “_rule02”, etc.
This works:
tell window "wndDataEntry"
set visible of text field "_rule01" to false
end tell
This doesn’t:
set s to "_rule01"
tell window "wndDataEntry"
set visible of text field s to false
end tell
I get an NSReceiver… error - didn’t quite catch the whole phrase.
I’ve tried …as text, …as Unicode text, …as string, etc. How can I cycle through this list?
I created a little test app that consists of a window, a button and 4 text fields and the code below works as expected.
property theLines : {"Line1", "Line2", "Line3", "Line4"}
on clicked theObject
set theLine to some item of theLines
if the visible of text field theLine of window "Main" is true then
set the visible of text field theLine of window "Main" to false
else
set the visible of text field theLine of window "Main" to true
end if
end clicked
With NSReceiver errors the first thing I always do is make sure I don’t have any typos.
Wow…thanks Brad. I’ve been on this a solid day, but if that works for you then I’ve got to dig elsewhere, I guess. It just seems odd that the only difference is the indirection of the text designation. Well…
Out of curiosity I changed my code to use a “tell window…” structure. Still works as advertised.
property theLines : {"Line1", "Line2", "Line3", "Line4"}
on clicked theObject
set theLine to some item of theLines
tell window "Main"
if the visible of text field theLine is true then
set the visible of text field theLine to false
else
set the visible of text field theLine to true
end if
end tell
end clicked
If nothing else that SHOULD help to eliminate one possible cause of the problem.
I’ve tried it both ways. To get past it for now I’m using an if-then-else construct that makes my blood run cold. I’ve scrutinized this for typos which of course I never make :rolleyes: (my next one will be my fisrt.)
Hi kel - That’s among the many permutations I’ve tried (text view, text field, text view of text field…, text field of text view…, and all sorts of other (many illogical) combinations). I’m still not straight on the relationship among text view, scroll view, etc., but I think I exhausted all possibilities.
Okay, I think I know the problem, but not the solution. (It’s not just the visibility property, of course.) If I say
tell window "wndDataEntry"
set s to "lblProc01"
text field s
end tell
it works. If I say
tell window "wndDataEntry"
set s1 to "lblProc"
set s2 to "01"
text field (s1 & s2)
end tell
it works. But I’m generating these numeric suffixes (“01”, “02”, etc.) from a little handler that prepends a “0” if it’s less than 10, so these strings aren’t around at compile time (which appears to be necessary), so this does NOT work:
tell window "wndDataEntry"
set s to "lblProc" & my prepend(n)
text field s
end tell
I guess I’ll just keep a list of {“01”, “02”, “03”, …} around. In retrospect I didn’t give enough info in my original post or else one of you probably would have caught it.