Newbie Question on Repeat Loops for Scripting Interarchy FTP App

Hello everyone,

I’m new to Applescript, and am excited about learning the language. I am a big user of LiveCode, which is a cross-platform incarnation of HyperCard, so Applescript strikes me as somewhat familiar.

I need to download a bunch of files from the Security and Exchange Commission’s public FTP site. Happily, I was able to write the script to download one file using Interarchy. Here is my first little script.


tell application "Interarchy"
	fetch alias "Blue Note:Users:me:Downloads:theFilename.txt" host "[url=ftp://ftp.sec.gov]ftp.sec.gov[/url]" user "anonymous" password "myEmailAddress" path "edgar/data/704432/0000950110-99-000960.txt"
end tell

But I have hundreds of urls, like the one in the script above, of files that I want to download. These are stored in a text file with one url per line. How would I have Applescript set a variable to the content of the file of urls and then repeat my fetch statement for each line (url)? I’m guessing it involves a repeat-with loop.

Any tips would be much appreciated.

Regards,

Gregory

Assuming your text file is plain text in paragraphs, you should read the file with the addresses into a list:


set tURLs to paragraphs of read (path to file)

The easy way to get the path into your script is simply to drag the file where you want the path and choose the alias form. Then


repeat with oneURL in tURLs
-- and here you insert your handler for Interarchy.
end repeat

In your script, you don’t establish where the downloaded script is going – you’ll need to do that.

Hi Adam,

Much obliged. Looks like using the read command without first asking that the file be opened for access simply reads the entire file, and in that way works just like the put command in HyperCard and LiveCode.

I give it a whirl.

Thanks again,

Gregory

Hey Lypny,

Adam has given good advice.

However he’s mistaken about this.

Firstly “ you did provide a download path in your original script with the given alias.

Secondly “ you don’t need to do so.


tell application "Interarchy"
	fetch url "ftp://ftp.sec.gov/edgar/data/704432/0000950110-99-000960.txt"
end tell

For anonymous ftp this works just fine and downloads to your default location.

So looping through a list of URLs is quite easy.


Chris


{ MacBookPro6,1 · 2.66 GHz Intel Core i7 · 8GB RAM · OSX 10.11.1 }
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

Even better. Thanks, ccstone.

Gregory

Thanks cstone – I don’t use Interarchy any more – I use Transmit.

Might be easiest to just do this from the terminal:

xargs -n1 curl -LO < urls.txt

I can’t import the URLS from a text file into the variable theURLS.

My script fails at


set theURLs to paragraphs of read “/Users/gregorylypny/Desktop/Accession Numbers Test.csv”


Syntax error?

I will also look into curl. Can’t hurt.

Gregory