sending right arrow to htmlviewer, applescript, ui browser

I’d like to send a right arrow key press to an htmlviewer. I’ve tried various versions in Applescript along the lines of:

tell application "System Events" tell process "cbz4.debug" keystroke (ASCII character 29) end tell end tell

None of which worked. I opened up my trusty copy of UI Browser (http://pfiddlesoft.com/uibrowser/) which is great for telling you what’s going on in app in an Applescript context. In UI Browser I can send a right arrow and i can see my htmlviewer reacting to it. But, I can’t figure out how UI Browser is doing it.

So, does anyone know of a good way to send a right arrow key to an htmlviewer, or is someone here familiar enough with UI Browser to help me figure out the Applescript commands it is sending?

what are you trying to accomplish by sending the right arrow ?

What I’m currently doing is accessing a javascript slideshow via htmlviewer, entering and saving an annotation locally and then clicking the right arrow key to progress to the next slide. I’m trying to cut out that extra keystroke and have just one key stroke to submit the annotation followed by the progression to the next slide.

I think your using the Applescript keystroke command incorrectly, I recently answered a question about the Applescript keyboard commands on another forum recently, so instead of me rewriting the advise, here’s a link to that forum post.

http://www.mac-forums.com/forums/os-x-development-darwin/306818-applescript-function-key.html

Regards Mark

EDIT - Norm fixed the URL posted

Sorry I got the link bit wrong, but I’m sure you can copy and paste it into the address field of your browser, as I cant figure out how to edit the post.

Mark

Yeah i’ve tried various commands with both keystroke (ASCII character 29) and key code 124

UI Browser makes it look like the commands it is using are:

activate application "cbz4.debug" tell application "System Events" tell process "cbz4.debug" tell scroll area 1 of window "CBZ 4" keystroke (ASCII character 29) end tell end tell end tell

but I can’t get that to work. It may have something to do with focus and I’m currently testing directing the commands to various parts of the htmlviewer.

Yeah it’s definatly a focus issue, the Applescript keystroke command only sends to the currently active keyboard cursor object.

Also when using UI scripting, the application your trying to access has to be a scriptable application, which means that if your trying to tell a particular UI object to do something, then that same UI object has to accessible by being a scriptable object.

So "tell scroll area 1 of window “CBZ 4” means nothing to Applescript.

Regards Mark

When you press the right arrow key, the slideshow moves to the next picture, so I’m going to go out on a limb and guess it is using some form of JavaScript to do that, so why not just call the JavaScript directly?

I had thought of the javascript angle but there were so many parts in there (and not wanting to expand my limited javascript knowledge) I was having trouble figuring out which function was calling the next slide.

But, after much Applescript trial and error I found the step I was needing to set the focus. This works like a charm:

activate application "cbz4.debug" tell application "System Events" tell process "cbz4.debug" tell scroll area 1 of UI element 1 of scroll area 1 of window "CBZ 4" set value of attribute "AXFocused" to true keystroke (ASCII character 29) end tell end tell end tell

I found the deepest element that I could set focus on and then worked my way backwards until I found the shallowest group that I could set focus to and still react to the arrow. For instance, setting focus to the window or the first scroll area would not react to the arrow key. UI Browser was quite helpful in displaying and navigating all the nested elements in the htmlviewer.