• 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: Tell Safari to Download pdf?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Tell Safari to Download pdf?


  • Subject: Re: Tell Safari to Download pdf?
  • From: Ian Goos <email@hidden>
  • Date: Thu, 26 Jun 2008 13:38:26 -0400

This is mostly non AS:
I've used wget in the terminal to do this type of thing. It supports user names, passwords, cookies, base URLs, and text documents with lists of URLs/File Names. It also supports a number of other cool features like downloading entire web pages and support links (like PDFs) to create offline versions. I've used Fink to install wget and it is more simplified for my poor brain than curl is.


Capture the exit state of wget and act accordingly with AS, or set up folder actions as new files arrive.

wget does respect robot exclusions by default and I suspect curl does too. That could be why the activity is flakey.

Good luck!
On Jun 26, 2008, at 11:37 AM, Ken G. Brown wrote:


At 6:01 PM -0700 6/25/08, email@hidden apparently wrote:
Date: Thu, 26 Jun 2008 10:53:38 +1000
From: Alan Fairlie <email@hidden>
Subject: Re: Tell Safari to Download pdf?
<>
Here's an Apple example script using 'URL Access Scripting' for
downloading a file to a specific location.

set weather_map to "acttemp_720x486.jpg" -- temperatures
set weather_map to "curwx_720x486.jpg" -- surface isobars

set the target_URL to "http://maps.weather.com/images/maps/ current/" &
weather_map
set the destination_file to ((path to desktop as string) &
"weathermap.jpg")


tell application "URL Access Scripting"
	download target_URL to file destination_file re

Thanks a bunch for all the tips everyone, I've managed to get it working.


The site I am working with is http://www.freepatentsonline.com and they restrict downloads to those that have an account and are signed on.
I have a list of patents in a text file that I want to download.
I could not get curl to work for that reason but will file away that for future reference. Curl allows for user and password options but it did not work for some reason. From looking at the manual, curl is amazing tho. Files download but are incomplete.


I did not know about "URL Access Scripting" so that too might come in handy, but it did not work either, probably uses curl.

The trick I needed was of course to set Safari to download instead of display pdf's, which you need to set in Adobe Reader, not sure how to do it by scripting Safari.
Then set Safari download folder to what you want, sign on to freepatentsonline and this script or some modification thereof should work:


-------------------
-- loads a list of patent numbers from a file, then downloads their pdf's from freepatentsonline
-- must be signed in to the freepatents online site in Safari
-- Set Safari to download pdf's instead of displaying them, set download folder to an appropriate folder
tell application "BBEdit"
activate
open {file "yourpath:PatentList.text"} with LF translation
set myText to text of document 1 as text
end tell


set textList to every paragraph of myText
set urlBasePAth to "http://www.freepatentsonline.com/";
set mycount to count of textList

repeat with ii from 1 to mycount
set thisPatentNum to the last word of item ii of textList
set thisUrl to urlBasePAth & (thisPatentNum) & ".pdf"

tell application "Safari"
activate
make new document with properties {URL:thisUrl}

-- wait until document is finished loading, probably do not need this section in this application but might be handy for other types of pages
set myjavascript to "document.location='" & thisUrl & "'"
repeat until ((do JavaScript "document.readyState" in front document) is "complete")
delay 0.2
end repeat

delay 5 -- to give time for the downloads to start and even perhaps complete so don't get too many active at one time

-- close the windows so we don't get too many hanging around
set mycount to count of windows
repeat with jj from 1 to mycount
set this_win to (window (mycount - jj + 1))
close this_win
end repeat
end tell
end repeat


-------------------
Thx,
Ken G. Brown
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (applescript- email@hidden)
Help/Unsubscribe/Update your Subscription:
40link33.com
Archives: http://lists.apple.com/archives/applescript-users


This email sent to email@hidden

_______________________________________________ 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: Tell Safari to Download pdf? (From: "Ken G. Brown" <email@hidden>)

  • Prev by Date: Re: Finder 'update' command broken?
  • Next by Date: PhotoShop Spot Channels
  • Previous by thread: Re: Tell Safari to Download pdf?
  • Next by thread: [Re] Airport Utility Scripting
  • Index(es):
    • Date
    • Thread