Your best friend for file transfer.

Fetch application logoFetch

uploading a randomly-selected file (2 posts)

This is an archived topic. The information in it is likely to be out-of-date and no longer applicable to current versions of Fetch.
  • Started 19 years ago by davis_fields
  • Latest reply 19 years ago from Jim Matthews
  • davis_fields Member

    There's a trick I'd love to be able to do with Fetch: point it to a directory full of images (either on my hard drive or my Web server), give it a URL to upload to, and specify an interval (like 5 minutes). Then every 5 minutes it would randomly select one of the files (or cycle through them in order, I don't care which), and upload it to the specified URL. This way, for example, I could have an image on my home page that would automatically change all the time (which makes the page more interesting). Anyone have a clue how to do this? I suspect it has something to do with scripting, but that it a topic I know zero about. Thanks!

    Posted 19 years ago #

  • Jim Matthews Administrator

    Here's a script that you can save as an application. When you run it it will ask you for a folder, a URL and a delay, and after that it will upload a randomly chosen file from the folder to the URL you name, wait the specified number of seconds, and do it again -- until you quit it.

    property sourceFolder : ""
    property destinationURL : "ftp://userid:@hostname/path/filename"
    property delaySeconds : "300"

    set sourceFolder to (choose folder with prompt "Choose folder to upload files from:" as string)
    set dialogReply to display dialog "Enter the URL to upload files to, including filename:" default answer destinationURL
    set destinationURL to text returned of dialogReply
    set dialogReply to display dialog "Enter the number of seconds the script should wait between uploads:" default answer delaySeconds
    set delaySeconds to (text returned of dialogReply as integer)

    on idle
    tell application "Finder"
    set fileCount to count of files in folder sourceFolder
    set randomFile to (file (random number from 1 to fileCount) of folder sourceFolder as string)
    end tell

    tell application "Fetch 4.0.3"
    store file randomFile url destinationURL
    end tell

    return delaySeconds
    end idle

    Let me know if you have any trouble with this, or if you'd rather have a script that copies a file from a server instead of from a local folder.


    Jim Matthews
    Fetch Softworks

    Posted 19 years ago #

Topic closed

This topic has been closed.