Hit 'Enter' within a UI search field in Amazon's Kindle application

I am trying to script the UI of 'Kindle", an application by Amazon managing the ebooks purchased through their site.

A main window lists all books and a search field lets the user search for specific books.

The following script will insert the word “big” in the search field:

activate application "Kindle"
tell application "System Events"
	tell process "Kindle"
		set frontmost to true
		tell window 1
			tell toolbar 1
				tell group 3
					tell text field 1
						set value to "big"
					end tell
				end tell
			end tell
		end tell
			end tell
end tell

Now, whereas typing “big” manually in the application would automatically filter the list of books, inserting “big” through Applescript still requires the user to press the enter key for within the search field.

Adding the line

tell application "System Events" to key code 36

does not help within the ‘text field 1’ tell block, nor within any other tell block.

How can I script pressing the enter key within the search field?
Alternatively, if my approach is flawed altogether, I would appreciate suggestions to accomplish what I need, which is to download on the Mac a book archived in the cloud.

Many thanks! W.

Hello.

I’d try:

set value to "big
"

Hi,

Try ‘keystroke return’.

activate application "Kindle"
tell application "System Events"
	tell process "Kindle"
		set frontmost to true
		tell window 1
			tell toolbar 1
				tell group 3
					tell text field 1
						set value to "big"
					end tell
				end tell
			end tell
		end tell
	end tell
	keystroke return
end tell

gl,
kel

McUsrII and kel1,
Thank you for your suggestions, but unfortunately neither works.

I tried “big\r”, “big\n” and (“big” & return), to no avail.

I tried “keystroke return” in all tell blocks. I also tried inserting a delay before the keystroke. Still nothing.

All further suggestions will be very welcome. W.

My understanding is that the application doesn’t respond to keystroke issued thru GUI scripting.
When I run your script, the search field is filled but the search doesn’t apply.
If I press return by hand, the search is executed.

Yvan KOENIG (VALLAURIS, France) jeudi 21 août 2014 12:12:34

I found the following solution, using the “Find” command in the “Edit” menu of the Kindle application:

activate application "Kindle"
tell application "System Events"
	tell process "Kindle"
		keystroke "f" using command down
		delay 1
		keystroke "big"
	end tell
end tell

I am surprised that it works, because manually typing ⌘F just puts the cursor inside the search box that I was trying to manipulate in the first place… Also, the delay seems to be indispensable.

Anyway, that solves it. Thanks again to everyone who contributed ideas! W.

I tried keystroke “big” but got no result, probably because I didn’t inserted the delay just before.

Yvan KOENIG (VALLAURIS, France) jeudi 21 août 2014 15:24:32

Hi wladdy,

I think you can set the focus to the text field with ui element scripting also.

gl,
kel

Hello wladdy.

That was a nice solution, thanks for sharing. :slight_smile:

And thanks to you Yvan, for sharing the experience of ignored returns in UI scripting. :slight_smile:

Hello kel1

It’s what our friend did.
When he issue keystroke “f” using command down, the focus is automatically set to the correct text field but this requires some time which is why he use delay 1.
I’m quite sure that this delay is too long but I’m too busy to restart Kindle for tests.
Tomorrow I will try with .5 and if it’s OK I will try with .2 .

I’m really puzzled by the apparent inability to treat keystroke return because, as I already wrote, if I press return by hand when the field is filled by set value of. the search is executed.
As you probably already know, I’m pig headed and have some difficulties to leave a problem before understanding it.

Yvan KOENIG (VALLAURIS, France) jeudi 21 août 2014 21:16:27

Thanks McUsrII

Just to be sure that everybody understand well,I wish to add that it’s only when I tried to trigger the Kindle process that keystroke return does seemingly nothing. It works well with every other process which I already triggered.

Yvan KOENIG (VALLAURIS, France) jeudi 21 août 2014 21:23:57