| |
| | |

Apple Phoon Forum

 Forgot password?
View: 632|Reply: 3

How can Applescript if a "UI" Script Was Successful?

[Copy link]

Post time: 2014-01-10 05:53:53 |Show all posts
AppleScript,  Unix
I'm making an Auto-Launching script, for Minecraft. The script is right now over 500 lines, so every less line and every less variable counts. What I need is something to detect if a UI script was successful or not. In this case, checking if the "Login" button was pressed. I'm distributing this to hundreds of people so each persons "Minecraft" will load for a different length, so it must keep trying until succession. The script I have right now is:
try tell application System Events click button Login of window Minecraft Launcher of application process JavaApplicationStub end tellon error delay 0.5end try
I have that particular action multiple times in a row. This means that no matter what it will take multiple seconds because it tries each time, even if the action was already completed. If possible, I'de not like to get into reading the raw Booleans for the answer, as many people modify their Minecraft. As a requirment, it needs to fit into an "If, Then" statement. Thanks in advance. The quotations aren't showing up in the script snippet, but everything in red is covered by them.

Use magic Report

Post time: 2014-01-10 09:36:10 |Show all posts
An error in the try statement will cause execution to jump to the on error part, but if there is no error the exit repeat statement will exit the loop.

Use magic Report

Post time: 2014-01-10 08:09:53 |Show all posts
But then how/why will the repeat stop? I have bad experiences with making loops like that. 2 Days ago I had to wipe my Mac because my app with a loop like that went crazy and messed around with about every plist in sight. Even the Genious Bar couldn't help me, wouldn't this do the same?

Use magic Report

Post time: 2014-01-10 07:01:34 |Show all posts
If I understand you correctly, you can put your command inside a repeat loop, and exit if there is not an error. I would think that there is a better way, but using your example it would be something like:
repeat -- forever
tell application "System Events"
click button "Login" of window "Minecraft Launcher" of application process "JavaApplicationStub"
end tell
exit repeat
on error -- no button, so wait and try again
delay 0.5
end try
end repeat


Use magic Report

You have to log in before you can reply Login | Register

Archive| Apple Phoon

2021-04-18 07:32 GMT-8 , Processed in 0.066691 sec., 27 queries .

Powered by Discuz! 7.2

Release 20121101, © 2001-2021

To Top