1
try set logindetails to (do shell script "curl google.com") on error display dialog "Unable to connect." quit end try 

When I put my network down, it gives me an error saying "unable to resolve host" and it never quits the application rather it stays in the background.

Is there a proper way to quit the application when unable to connect to the server or any other command to force quit or suppress and continue.

2 Answers 2

2

The correct way to end a running script is to use return:

try set logindetails to (do shell script "curl google.com") on error display dialog "Unable to connect." return end try 

See the AppleScript Language Guide’s pertinent section.

Sign up to request clarification or add additional context in comments.

5 Comments

I did use return but the application doesn't quit. It remains in the background. I tried with on idle as my application continually runs in the bckgrd and also tried without on idle. It does work. It basically doesn't quit because it looks for the unresolved host and never completes the task which it needs to quit. Any other solution?
Is curl actually returning? Try adding --max-time 15 to the curl command to time out the connection after 15 sec.
curl is getting stuck at this point waiting for the response and the application gets stuck here. I then have to force quit. I want to continue at this point when the connection with server breaks. I tried --max-time 15 but it doesn't after a succesful connection and then when connection breaks and this app runs in the background with on idle.
You might be able to alleviate the issue but wrapping the set command in a with timeout block – however, it would be much easier to find a solution if you posted your actual code (I’m guessing you are not actually polling Google for login credentials); just obfuscate sensitive data like passwords or such, please.
It worked for me when I used -max -time interval. curl --max-time 5 -d \"username=" & loginusername & " \" " & domain & "/playlists.php. Yes i was not using google to pull data. This line of code is the real code. Thanks.
1

I use error number -128:

try set logindetails to (do shell script "curl google.com") on error display dialog "Unable to connect." error number -128 end try 

2 Comments

What is this code going to do? I want to avoid error dialog box to appear. I will try this out though.
Exact same thing as calling return – actually, that is the error code the script returns with when you call call return:).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.