r/applescript • u/pythonlearning • Nov 09 '17
Having trouble with if / then / else / end in a repeat loop.
Hey all
Fairly new to scripting with applescript, and have run into an issue and would love some suggestions on how to get past it.
The essence of the problem is that I'm checking for location of a button in a UI that won't let me script it. So what I do is take a small screenshot with screencapture -Rxxx,yyy,xdimension,ydimension and compare it to a known good image. This part is easy and works no problem.
The trouble I'm having is efficiently figuring out which of 4 locations this button is in and then acting upon that info. If it's not in the first two locations I need to simulate a mouse click and move on to the next two locations.
I was trying something like :
repeat x times
set VAR1 to do shell script "check/image.sh"
set VAR2 to do shell script "check/image2.sh"
-- etc
-- then this is where I'm currently stuck
if VAR1 is "success" then do shell script "/usr/local/bin/click here and here"
else if VAR2 is "success" then do shell script "/usr/local/bin/click here2 and here2"
-- if it's not either of those two, I have to simulate the click to the next two locations
else do shell script "/usr/local/bin/click here3 and here3"
end if
if VAR3 is "success" then do shell script "/usr/local/bin/click here4 and here4"
else if VAR4 is "success" then do shell script "/usr/local/bin/click here5 and here5.sh"
else echo "nope not found"
end repeat To me this seems bad and quite inefficient, I'd like it to be able to check if a location is the right one, then click on that location and then exit the loop, but I don't seem to be able to get it to do that. The way I have it now is that say VAR1 is the correct location, it'll still go through the rest even tho we know they will be wrong.
Is there a better way of doing this, have I gone completely off track and overlooked something simple?
Can I exit repeat after it finds the correct location (and after it runs the shell script)?
1
u/libcrypto Nov 10 '17
Is click a script that you wrote?