Hello guys!
Sorry if this problem was already posted but i could’n find the answer by searching the forum (of google for that matter).
So here goes:
I am working on a UI script that is supposed to click some buttons in the console of an application and then take screenshots of the subsequent views that are opened.
Seeing that the are a lot of buttons, i’d like to make a list of them and then just send it to a repeat loop.
Something like:
set uiElements to {element1, element2, …}
repeat with every element in uiElements
click element
takescreenshot()
end repeat.
The problem is that the list cannot take the full “name” of the buttons. The list right now looks like this:
set ElementsList to {“button 1 of list 1 of group 2 of window "My application"”, ¬
“button 2 of list 1 of group 2 of window "My application"”}
When running the script like this, the results tab says:
click “'button 2 of list 1 of group 2 of window "My application"”
This will obviously not work because click does not recognize the string as a clickable item.
The correct way would be:
click button 1 of list 1 of group 2 of window “My application”
Could somebody please help me? I’ve been at this for a couple of days and to no avail.
Sorry if i wasn’t explicit enough, please ask away if you have any questions.
Thank you for your time!
Only System Events knows about clicking and buttons and stuff. So put your “correct” command inside a tell block. Note you also have to tell a process too… something like this…
tell application "System Events"
tell process "My application"
click button 1 of list 1 of group 2 of window "My application"
end tell
end tell
That’s exactly what i am trying to do. But instead of the click button 1 of list 1 of group 2 of window “My application” line, i want to have something like
set UIList to {button 1 of list 1 of group 2 of window "My application", button 2 of list 1 of group 2 of window "My application", etc... }
tell application "System Events"
tell process "My application"
repeat with button in UIList
click button
end repeat
end tell
end tell
The problem is that applescript cannot interpret correctly the elements in the list.
I also have another problem with the script:
I’m using the following command to take screenshots of my application’s windows
do shell script "screencapture -w " & pathToPicture
Problem is, screencapture stops the script from running because it waits for me to click a certain window.
Running the command with a trailing "&" does not seem to work either.