• 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 into a folder (still)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: downloading a file into a folder (still)


  • Subject: Re: downloading a file into a folder (still)
  • From: kai <email@hidden>
  • Date: Wed, 23 Feb 2005 03:53:30 +0000


On Tue, 22 Feb 2005 11:08:17 +0100, Christian Vinaa wrote:

this works for me (thanx to various input from this list)

set myTime to (current date) as text
set theTime to characters -8 through -1 of (myTime) as text
set theGoodTime to characters 1 through 2 of theTime & "-" &
characters 4 through 5 of theTime & "-" & characters 7 through 8 of
theTime as text

set myDay to the day of (current date) as text
set myMonth to the month of (current date) as number
set myGoodMonth to (text -2 thru -1 of ("00" & (myMonth)))
set myYear to the year of (current date) as text
set myName to myYear & "." & myGoodMonth & "." & myDay & "_" & theGoodTime


set this_URL to "http://webcam.aet.ch/traffico/airolo_s.jpg";

set myFileName to myName & ".jpg"

do shell script ("curl " & this_URL & " -o " & quoted form of POSIX
path of (((path to desktop) as string) & "SBB Webcam:" & myFileName))

save picture with date/time-stamp; neat !

Well done, Christian.

I hope you won't mind if I add one or two observations. I notice that your script calls the 'current date' event from Standard Additions a number of times, which carries an overhead. In this kind of situation, it's more efficient to make one such call - and then extract the bits that you want from a variable:

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

set currDate to current date (*don't coerce to a string here*)
set theTime to currDate's time string
-- etc...

set myDay to currDate's day
set myMonth to currDate's month
-- etc...

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

In addition, if you want your script to be portable, it's an idea to think about the different date and time settings that a system might have. For example, when I just ran the first few lines of your script, the variable 'theGoodTime' returned a value of "52-24-am". In other words, I'd lost the hour value - and was left with the minutes, seconds and am/pm string. (No biggie if a script is purely for your own use - but perhaps something to consider for the future...)

I see that in the end, you went for the shell script option - in which case you could probably condense the above script a bit further (one line - watch for wraps):

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

do shell script "curl " & "http://webcam.aet.ch/traffico/airolo_s.jpg"; & " -o " & quoted form of (POSIX path of (path to desktop) & "SBB Webcam/") & (do shell script "date +%Y.%m.%d_%H-%M-%S.jpg")

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

(If anyone else wants to try this, create a folder on your desktop named "SBB Webcam" first.)

---
kai

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: downloading a file into a folder (still)
      • From: kai <email@hidden>
  • Prev by Date: Translating AppleScript to Visual Basic
  • Next by Date: Re: downloading a file into a folder (still)
  • Previous by thread: Re: Translating AppleScript to Visual Basic
  • Next by thread: Re: downloading a file into a folder (still)
  • Index(es):
    • Date
    • Thread