Downlaoding a number of sequential files from a website

I have a number of PDFs sequentially numbered that represent a training manual that I need/have to read. There are about 45 of them.

How would I formulate a script that would open each of these files.

Catch… The files are on a webserver that requres a login/password. A cookie is then passed to the browser so that accessing other pages does not require said password.

Any ideas?

What browser are you using? Does each file have its own sequentially numbered URL?
SC

Safari… and yes… they are sequentially numbered URLs

For example, if the URL

http://www.macscripter/helppages/1.pdf” has 25 other available, ending with
http://www.macscripter/helppages/25.pdf

The following script gets them all with this dialog:

“Type the portion of the URL preceding the page counter” (Or paste)
http://www.macscripter/helppages/

“Type the first page number”
1

“Type number of pages to load”
25

“Type the rest of the URL”
“.pdf”

set URLBase to display dialog "Type the portion of the URL preceding the page counter" default answer ""
set URLBase to text returned of URLBase

set URLNum to display dialog "Type the first page number" default answer "1"
set URLNum to text returned of URLNum

set LastURLNum to display dialog "Type number of pages to load" default answer "1"
set LastURLNum to text returned of LastURLNum

set URLEnd to display dialog "Type the rest of the URL" default answer ""
set URLEnd to text returned of URLEnd


set VariableURl to URLBase & URLNum & URLEnd as string

tell application "Safari"
	make new document at the beginning of documents
	set the URL of the front document to VariableURl
end tell

delay 5


repeat (LastURLNum - 1) times
	
	set URLNum to (URLNum + 1)
	set VariableURl to URLBase & URLNum & URLEnd as string
	
	
	tell application "Safari"
		set the URL of the front document to VariableURl
	end tell
	
	delay 5
	
end repeat

tell application "Safari" to close window 1

Let me know if it works, it works great here…
SC

One note… the delay times allow the file to load. If your download times take longer than 5 seconds, set the delay to “a few seconds more than it takes to download the file”

Hello sitcom and nitefall,

I’d suggest a solution involving the shell… Advantage: Shorter AppleScript code, and you can execute it while surfin’ with Safari :slight_smile:


on run
	set first_part to (text returned of (display dialog "Enter the first URL Part" default answer ""))
	set num_range to (text returned of (display dialog "Enter a range (i.e. 1-100) for the numbers:" default answer ""))
	set last_part to (text returned of (display dialog "Enter the last URL Part" default answer ""))
	
	set my_command to ("curl -fs " & first_part & "[" & num_range & "]" & last_part) as text
	
	with timeout of 300 seconds
		set my_result to do shell script my_command
	end timeout
	
	if my_result > 0 then
		display dialog (("An error occured, the number is " & my result) as text)
	else
		display dialog "Okey, dokey, I'm done!"
	end if
end run

Note: This is a “hack from the head”, i.e. I’ve just hacked it in without testing it. You may check what the shell command does by reading the manpage for curl (open a Terminal, enter ‘man curl’ (w/o quotes) and hit Enter)

Regards,
Daniel

Model: iBook (g3/800, 14,1")
AppleScript: 1.9.3
Browser: Safari 312
Operating System: Mac OS X (10.3.9)