property script_name : "Get URL Source"
property script_description : "Returns the source of a URL (or the combined source of multiple URLs) as a string without the overhead of a browser."
set the_url to "http://www.macscripter.net" --single URL string or list of URL strings
return get_URL_source(the_url)
on get_URL_source(the_url)
if class of the_url = string then
set the_script to "cURL " & (quoted form of the_url)
else if class of the_url = list then
set the_script to "cURL "
repeat with i from 1 to count of the_url
if class of (item i of the_url) = string then
set the_script to the_script & " " & (quoted form of (item i of the_url))
else
return "error: the submitted parameter is not a string or list of strings."
end if
end repeat
else
return "error: the submitted parameter is not a string or list of strings."
end if
return do shell script the_script
end get_URL_source
Now i was wondering if anyone could make a dialog box(i know how to do this) (but not the following) and whatever the user enters it gets that url source EG:set the_url to “http://www.macscripter.net” --single URL string or list of URL strings where it says set the_url to “macscripter.net” is it possible to make the url what ever the user enters?? THANKS IN ADVANCE, JDogg!
Model: Imac DV SE 33 Mhz,Power book G3 333 mhz
AppleScript: 1.10.6(2.1.1)
Browser: Firefox 1.5.0.4
Operating System: Mac OS X (10.4)
Not sure if your looking for something like this but hear goes…
set k to display dialog "Enter just the name of the webpage without the www. and .com bits" default answer "macscripter"
set y to text returned of k
set x to "http://www." & y & ".com" as string
display dialog x
as string is not needed here. The first item is a string, so the other items will be coerced as needed. Also, at some point (AS 1.9.2, OS X v10.3) display dialog started returning Unicode text; Using as string explicitly like this may affect the Unicode.
I’ve been more pedantic about this because I keep seeing problems because of it.
set test1 to "hello" as string -- `as string` is unnecessary
set test2 to {"a", "b"} as list -- `as list` is unnecessary
-- this adds test1 to test2, but then turns that list into a string. Very bad when you don't expect it!
set whatever to test2 & test1 as string --> "abhello"
-- still unnecessary in this case, but it shows how to use parentheses to make sure you coerce the right value
set whatever to test2 & (test1 as string) --> {"a", "b", "hello"}
I think its a force of habit sometimes to just try an stick an “as whatever” coercion on the end of a line of code.
when things aren’t working right…
Just down to inexperience i guess.
i’m very happy for you to pick me up on it though, cause i think it sinks in abit better…
or i hope it sinks nonetheless!!!
Perhaps this would be what you want. (Note, BTW, that the text returned of a dialog is Unicode text, not a string):
property script_name : "Get URL Source"
property script_description : "Returns the source of a URL (or the combined source of multiple URLs) as a string without the overhead of a browser."
set theSources to {}
set done to false
repeat until done
set msg to {button returned, text returned} of (display dialog "Enter one or more URLs" & return & "Do not include http://" default answer "bbs.applescript.net" buttons {"Cancel", "Add More", "Done"})
if item 1 of msg is "Done" then set done to true
set the end of theSources to do shell script "curl " & "http://" & item 2 of msg & "/"
end repeat