Re: Test for valid URL?
Re: Test for valid URL?
- Subject: Re: Test for valid URL?
- From: Michael Grant <email@hidden>
- Date: Fri, 17 Sep 2010 20:44:27 -0500
On Fri, Sep 17, 2010 at 3:00 AM, Thomas Fischer <email@hidden> wrote:
> Hi Michael,
>
>
>>> A couple of other people have mentioned that the word "valid" is ambiguous
>>> but for "standard" URLs this works
>>> try
>>> do shell script "curl http://hgghjgjhghj/"
>>> on error
>>> display dialog "No a valid URL"
>>> end try
>>> If curl can't resolve the url it returns an error which AppleScript's try
>>> statement can catch.
>>> Steve
>>
>> Thanks to everyone who has replied so far. Actually I do want to be
>> able to respond to different protocols, not just http, for both local
>> and network resources. Unfortunately neither
>>
>> open location "some random string"
>>
>> nor
>>
>> do shell script "curl some random string"
>>
>> actually returns an error on my system (the first one returns nothing,
>> the second returns an empty string), and they both just fail silently
>> if I wrap them in Steve's try block.
>
> This sounds like a problem of your system.
> On my system (10.6.4, using AppleScript-Editor):
>
> do shell script "curl some random string"
> --> error "\rcurl: (6) Couldn't resolve host 'some'\r\rcurl: (6) Couldn't resolve host 'random'\r\rcurl: (6) Couldn't resolve host 'string'" number 6
>
> You may want to try curl on the command line (in the Terminal) to see if something goes wrong there.
>
>
> So I would suggest to use something like this:
>
> try
> do shell script "curl http://hgghjgjhghj/"
> on error theErr
> display dialog "Problem: " & theErr
> end try
>
> which should yield
>
> tell current application
> do shell script "curl http://hgghjgjhghj/"
> --> error "\rcurl: (6) Couldn't resolve host 'hgghjgjhghj'" number 6
> end tell
> tell application "AppleScript Editor"
> display dialog "Problem: \rcurl: (6) Couldn't resolve host 'hgghjgjhghj'"
> --> {button returned:"OK"}
> end tell
>
> I thought you where looking for something like this.
>
> Furthermore if you just want to check if the URL works w/o downloading the file, you can use
>
> do shell script "curl --head http://hgghjgjhghj/"
> or
> do shell script "curl -I http://hgghjgjhghj/"
> (the same effect) to load only the HEAD response from the server.
I'm mostly a GUI guy and don't really know what to expect from curl, but running
curl some random text
in my Terminal on 10.6.4 produces no result — it just chews on it for
a few seconds, then displays a new prompt.
- Michael
--
There's really no such thing as translating. It's all a scam. We
basically just make stuff up and try to make it sound plausible.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden