 |
 |
Expert AppleScript advice needed
|
 |
|
 |
|
Forum Regular
Join Date: Oct 2000
Status:
Offline
|
|
If anyone can help me write a script to do the following (and actually explain the commands) I would appreciate it very much.
There is a file on a website. We'll call it http://foobar.com/image.jpg
I would like to check this file every 30 seconds. If the file has changed (check the modification date I guess) then download it.
Let's say the download location on my harddrive is "Macintosh HD:  ownloads"
When it saves the file, it should change the name and increment it according to what files already exist in the download folder. The file on the site is called "image.jpg" ; I want to save it as "image_nnn.jpg" where nnn is a number. If there is already previously saved images "image_001.jpg" and "image_002.jpg" the next save should be "image_003.jpg". Etc.
Basically, I want to check for changes in this file every 30 seconds. If it's changed, download it to disk, do not rewrite over the existing files but increment the number.
Sounds easy, but my knowledge of AppleScript is lacking.
I do have Interarchy (nee Anarchy) to use for HTTP/FTP. But if AppleScript has built-in http commands that would be nice.
(as a side note I can't wait for OSX because I could easily do this using a shell script, but trying to do this on Mac OS 9 with AppleScript confuses me greatly)
Thanks,
Ben
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Dec 2000
Location: Edmonton, Canada
Status:
Offline
|
|
Originally posted by nebben123:
If anyone can help me write a script to do the following (and actually explain the commands) I would appreciate it very much.
There is a file on a website. We'll call it http://foobar.com/image.jpg
I would like to check this file every 30 seconds. If the file has changed (check the modification date I guess) then download it.
Hi,
I don't know too much about AppleScript, but I do know that there isn't a built in way to get your mac to do scheduled things (a la crontab on UNIX) I just heard about this program 'ido' today from another macnn forum...you can get it to do things for you on the hour on certain days or every 30 seconds like you want. Check it out here:
http://www.apple.com/applescript/idosched/ido.html
It works great so far for me. (in the last hour or two that I've been playing around with it)
Hope this helps,
The Macho Man
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jan 2001
Location: Thionville, France
Status:
Offline
|
|
Hey, your wrong Macho Man. You CAN use AppleScript to do things regularly. Instead of putting your code inside a
on run
end run
statement, you put it in a
on idle
end idle
statement. If the script is saved as a "stay-open" application and you launch it, the script will stay quietly in the background and every 30 seconds (this is the default but you can change it adding a "return (number_of_seconds_before_next_check)" before the "end idle" statement) it will execute the content of the idle statement if it is not doing anything else.
This topic is perfectly explained in The AppleScript Language Guide (http://developer.apple.com/techpubs/macos8/InterproCom/AppleScriptScripters/AppleScriptLangGuide/index.html).
Now, Ben, the problem is that I'm pretty sure you can't get the creation date of a file retrieved from the web, unless the file was created on a Mac (even then, I'm quite sure you can't get it without actually downloading the file).
Gwenhiver.
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Oct 2000
Status:
Offline
|
|
Thanks for that info. I think you can get the creation date of the file somehow. I mean, when I go to the directory using a web browser and see the file, it shows the last modification date. Like this
image.jpg 30-Jan-2001 19:30 8k
meaning the file name is "image.jpg" it was last modified January 30th 2001 at 7:30pm and the file size is 8k.
I hope there is some way for applescript to get this info (even if it's from a third party app like Anarchie).
Ben
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jan 2001
Location: Thionville, France
Status:
Offline
|
|
Hmmm... You're right, you may be able to get this modification date right from the page, without downloading the file. I'm currently not at home, and can't look to the URL access AppleScript dictionary. I'll take a look at it and post back this evening (I'm French, so it will be the evening for me at least...).
Gwenhiver.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jan 2001
Location: Thionville, France
Status:
Offline
|
|
Sorry, I’m not your guy. I’ve taken a look to the URL Access dictionary, and there is no command to get a file’s modification date straight from the web. Since I do not use Anarchy, I don’t know how you could use it to suit your needs.
Maybe someone else knows?
Gwenhiver.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jan 2001
Location: Thionville, France
Status:
Offline
|
|
It’s me again. I think I have the answer to your problem (at least a partial one). In fact, there are a few examples in the AppleScript Guidebook “URL Access Scripting” (<http://www.apple.com/applescript/help_mods.html> ) which, combined together would be able to extract the modification date of a file, and retrieve it if needed to.
Unfortunately, I do not have the time to write you this script. Anyway, if you know a bit of AppleScript, you may be able to figure it out by yourself. Else, I hope someone will have some time to share. Everything seems clearly explained in the guidebook.
Good luck,
Gwenhiver.
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Apr 2000
Status:
Offline
|
|
You cannot check the modification date. It would be a futile effort to try.
What you CAN do though is make it check the byte count!
That COULD work but I'm not sure how to do it.
Or you can make it auto download, compare, and if its not any different, then delete it.
Is the continuous downloading an option?
EDIT:
Hm... Gwenhiver, I doubt it could check the date. What if the file isn't hosted on the MacOS? I just can't see it working. different OS's store dates in different ways. It'd be such a mess.
Not to mention how it'd do it
Cipher13
[This message has been edited by Cipher13 (edited 02-01-2001).]
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jan 2001
Location: Thionville, France
Status:
Offline
|
|
Well Cipher13, this is what I used to think. But if you get the URL Access AppleScript Guidebook from Apple's Site (the URL's above), you can see an example script that does just that. I didn't have time to test it, but maybe you would like to take a look at it.
Gwenhiver.
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Nov 1999
Location: Georgetown, Demerara, Guyana
Status:
Offline
|
|
Hi all,
Just wanted to add my vote for using Apple's 'URL Access Scripting' OSAX to retrieve a remote directory listing that could then be parsed to examine the "file date/time" field(s), as discussed in an earlier related ftp script wanted! thread in this Forum. As I also mentioned in that thread, there might be alternative ways of detecting whether a remote file has changed (depending on the particular type of server and/or file), such as examining the "file size" field.
[BTW, the relevant subsection of the AppleScript Guidebook's 'URL Access Scripting' (UAS) 1.5 help module is:- 'Introduction/How Do I... ?' -> 'get a listing of a network directory?'. The parsing example provided there is designed to handle certain directory listings where the file dates/times might not be in a consistent format. There is one necessary piece that seems to be missing from the 1.5 version of the UAS help module -- viz., the code to actually read the downloaded listing-file into memory prior to parsing -- but this can readily be accomplished via the standard file I/O commands of the 'Standard Additions' OSAX.]
One more thing, just in case you didn't already know it... To get the number of existing files in the local folder, so as to determine the "next" available filename-suffix, you could use AppleScript's built-in 'count' command on the (possibly unsorted) list returned by the Finder's "every file of folder-reference" command or by the stand-alone 'list files folder-path without invisibles' command, etc.
Regards,
--Paul
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|