Does anybody know a technique to query the current position of the "focus" in the Canon menus so it would be possible to know which menu item is selected when pressing the "set" button via script?
Since you're apparently still having trouble with reliably browsing the Canon menu, try replacing keypresses in the script with pairs of
post_levent_to_ui("PressSetButton")
post_levent_to_ui("UnpressSetButton")
commands. AFAIK the camera translates physical keypresses to these for internal use, and they may work more reliably.
The key strings you'll most likely need are
PressLeftButton
PressRightButton
PressDownButton
PressUpButton
PressSetButtonand their "
Unpress" pair, according to the example above. Upper and lowercase matters, you can find more strings in the firmware dump, or in strings.txt if you download the dump from the
http://tinyurl.com/chdkfiles2 repo.