• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Url Access Scripting
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Url Access Scripting


  • Subject: Re: Url Access Scripting
  • From: Christopher Stone <email@hidden>
  • Date: Tue, 28 Dec 2010 23:58:12 -0600

On Dec 28, 2010, at 21:14, Carl Anderson wrote:
I have this code segment
______________________________________________________________________

Hey Alex,

Okay; this works perfectly for me on 10.6.5:

set theURL to "http://members.aceweb.com/randsautos/photogallery/ferrari/enzo/Ferrari-Enzo-004.jpg"
set theFile to "/Users/chris/test_directory/Ferrari-Enzo-004.jpg"

tell application "URL Access Scripting"
with timeout of 60 seconds
try
download theURL to theFile replacing yes
on error the error_message number the error_number
display dialog DMo & DDa & DYr & "-Error: " & error_number & ". " & ¬
error_message buttons ("Cancel") default button 1
display dialog "Sorry, couldn't download the webpage" with icon 2
end try
end timeout
end tell

** Note that I dumped your 'file' reference and left in just the path, although your original syntax also worked just fine.

I too am inclined to recommend curl over url access scripting.  I use it daily, and I use wget quite often as well (downloaded and built with MacPorts).

SIMPLE:

set theURL to "http://members.aceweb.com/randsautos/photogallery/ferrari/enzo/Ferrari-Enzo-004.jpg"
set theFile to "/Users/chris/test_directory/Ferrari-Enzo-004.jpg"
set cmd to "curl " & (quoted form of theURL) & " -o " & (quoted form of theFile)
do shell script cmd

A LITTLE FANCIER:

set urlToCURL to "http://members.aceweb.com/randsautos/photogallery/ferrari/enzo/Ferrari-Enzo-004.jpg"
set newFile to "/Users/chris/test_directory/Ferrari-Enzo-004.jpg"

on CURL_TO_LOCAL_FILE(urlToCURL, newFile)
# Good practice: not all urls will parse correctly unless quoted.
# And curl doesn't like spaces in local path strings.
set quotedUrlToCURL to quoted form of urlToCURL
set quotedNewFile to quoted form of newFile


# Done this way so I can visualize the pieces of the command string when testing.
set cmdStr to {¬
"curl", ¬
"--location", ¬
"--user-agent 'Opera/9.70 (Linux ppc64 ; U; en) Presto/2.2.1'", ¬
quotedUrlToCURL, ¬
"--output " & quotedNewFile}


set AppleScript's text item delimiters to " "
set cmdStr to cmdStr as string
set AppleScript's text item delimiters to {""}
do shell script cmdStr
return (POSIX file newFile) as alias
end CURL_TO_LOCAL_FILE

CURL_TO_LOCAL_FILE(urlToCURL, newFile)

--
Chris
 _______________________________________________
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

  • Follow-Ups:
    • Re: Url Access Scripting
      • From: Christopher Stone <email@hidden>
References: 
 >Url Access Scripting (From: Carl Anderson <email@hidden>)
 >Re: Url Access Scripting (From: Wayne Melrose <email@hidden>)
 >Re: Url Access Scripting (From: Carl Anderson <email@hidden>)

  • Prev by Date: Re: Url Access Scripting
  • Next by Date: Re: Url Access Scripting
  • Previous by thread: Re: Url Access Scripting
  • Next by thread: Re: Url Access Scripting
  • Index(es):
    • Date
    • Thread