• 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: Downloading a file from the internet with a URL
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Downloading a file from the internet with a URL


  • Subject: Re: Downloading a file from the internet with a URL
  • From: Christopher Stone <email@hidden>
  • Date: Fri, 13 May 2016 03:18:41 -0500

Hey Ed,

It's generally a good idea to use an user-agent string if you're accessing servers you don't know; some of them don't especially like curl.

The Opera string is one I've used for years, but you can use any one you want.

This handler strives to make all of curl's used options easy to read and understand.  (Not all options in the comment listing are used.)

If you get to the point where you want to download multiple items then you'll want to learn how to use a config file.

See -K, --config in the man page.  The documentation for this isn't just wonderful, so holler at me if you want some help.

--
Take Care,
Chris

-------------------------------------------------------------------------------------------

set remoteURL to quoted form of "http://members.aceweb.com/randsautos/photogallery/ferrari/enzo/Ferrari-Enzo-014.jpg"
set destinationDirectory to "~/Downloads"

# Shell command for handler to extract the downloaded file name from verbose curl output.
set cmdStr to "| awk 'BEGIN { FS = \"/\" }; /Content-Location/ { print $NF }'"

# Download the file
set downloadedFileName to downloadFileToDirectory(destinationDirectory, remoteURL, cmdStr)
set downloadedFilePath to expandTildeInPath(destinationDirectory) & "/" & downloadedFileName
set downloadedFileAlias to alias POSIX file downloadedFilePath

-------------------------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------------------------
# --location         == -L             == Follow redirects
# --remote-name-all  ==  No Alternate  == Use the remote names of the downloaded files.
# --silent           == -s             == No progress bar
# --user-agent       == -A             == Employ a user-agent-string
# --verbose          == -v             == Verbose output
-------------------------------------------------------------------------------------------
on downloadFileToDirectory(destinationDirectory, remoteURL, cmdStr)
  if destinationDirectory starts with "~/" then
    set destinationDirectory to expandTildeInPath(destinationDirectory) of me
  end if

  

  set curlCMD to items 1 thru -2 of {¬
    "curl", ¬
    "-v", ¬
    "-A 'Opera/9.70 (Linux ppc64 ; U; en) Presto/2.2.1'", ¬
    "--remote-name-all", ¬
    remoteURL, ¬
    "2>&1", ¬
    ""}

  

  # “2>&1” --> allows curl's verbose output to be seen by AppleScript.

  

  set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, " "}
  set curlCMD to curlCMD as text
  set AppleScript's text item delimiters to oldTIDS

  

  set shCMD to "cd " & destinationDirectory & ";" & linefeed & curlCMD

  

  if cmdStr ≠ false and cmdStr ≠ "" then
    set shCMD to shCMD & space & cmdStr
  end if

  

  do shell script shCMD

  

end downloadFileToDirectory
-------------------------------------------------------------------------------------------
on expandTildeInPath(thePath)
  tell application "System Events" to return POSIX path of disk item thePath
end expandTildeInPath
-------------------------------------------------------------------------------------------

 _______________________________________________
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

References: 
 >Re: Downloading a file from the internet with a URL (From: Steve Mills <email@hidden>)
 >Re: Downloading a file from the internet with a URL (From: "email@hidden" <email@hidden>)
 >Re: Downloading a file from the internet with a URL (From: Yvan KOENIG <email@hidden>)
 >Re: Downloading a file from the internet with a URL (From: "Stockly, Ed" <email@hidden>)
 >Re: Downloading a file from the internet with a URL (From: "Stockly, Ed" <email@hidden>)
 >Re: Downloading a file from the internet with a URL (From: Rick Gordon <email@hidden>)
 >Re: Downloading a file from the internet with a URL (From: "Stockly, Ed" <email@hidden>)
 >Re: Downloading a file from the internet with a URL (From: Deivy Petrescu <email@hidden>)
 >Re: Downloading a file from the internet with a URL (From: "Stockly, Ed" <email@hidden>)
 >Re: Downloading a file from the internet with a URL (From: Deivy Petrescu <email@hidden>)
 >Re: Downloading a file from the internet with a URL (From: "Stockly, Ed" <email@hidden>)

  • Prev by Date: Re: Downloading a file from the internet with a URL
  • Next by Date: Re: Downloading a file from the internet with a URL
  • Previous by thread: Re: Downloading a file from the internet with a URL
  • Next by thread: Re: Downloading a file from the internet with a URL
  • Index(es):
    • Date
    • Thread