Hi, I am just starting with Applescript and I’m in need of some help.
I am trying to open a specific data file in Safari and download it to my hard drive. I can’t seem to get the save command to work. Any suggestions would be appreciated.
I have pasted the script at the stage I am at.
set theDate to current date
set dd to text -2 thru -1 of ("0" & theDate's day)
copy theDate to b
set month of b to January
set mm to text -2 thru -1 of ("0" & (1 + ((theDate - b + 1314864) div 2629728)))
set yyyy to year of theDate
set SD to yyyy & mm & dd
set FN to "pp" & SD & ".txt"
set UR to "http://www.cooltrader.net/730data/purepad/" & FN
tell application "Safari"
open location UR
save UR
end tell
Model: ibook G4
Browser: Safari 412.5
Operating System: Mac OS X (10.4)
Downloading the file: (note: It looks like you need a username and password to have access)
property url_start : "http://www.cooltrader.net/730data/purepad/"
property user_name : "username"
property user_password : "password"
tell (current date) to set url_end to "pp" & (10000 * year) + (100 * (its month)) + day & ".txt"
do shell script "curl -u " & user_name & ":" user_password & space & url_start & url_end
-- [ do shell script "curl http://username:password@www.cooltrader.net/730data/purepad/pp20051010.txt" ]
Query: Do you want to just save the file to disk and leave it or do you want to read the contents for use later on in the script? If you want to download it to disk, use the ‘-o’ parameter in curl.
Query: Do you want to just save the file to disk and leave it or do you want to read the contents for use later on in the script?
Firstly, thanks for your reply. I am new to the Mac switching from XP, so I’m getting used to the differences, but I commend Apple for the robustness and security of OS X.
I want to download these stock quotes found at the site mentioned and save the file. I do use a username and password, however, I have it stored in Safari, so it logs on automatically. (Whether this is wise or not I is subjective, but it is convenient.) Secondly, I would like to import the data into a Technical analysis program. Thanks, Rob
tell (current date) to set url_end to "pp" & 10000 * year + 100 * (its month) + day & ".txt"
I have a feeling that the Save command in Safari is still shot, Robert - so Qwerty’s curl suggestion might be a better option.
(If you really need to use Safari, it’s possible via UI scripting. Depending on any other requirements you might have, you could even save the source or just the text from Safari to file…)
Thanks for your reply. I’m still scratching because it seems the download won’t work because authorisation is required. I assume that is -u parameter in curl. I tried combining both but without success. Am I missing something?