Join the Stack Overflow Community
Stack Overflow is a community of 6.2 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am trying to write something that will detect a new file in a certain specified directory. I preferably would like this script to continue running indefinitely, and whenever I see a new file, I can copy it and move it somewhere else. I know this has to be possible, because dropbox does it, but I just do not know how to get this working or where to start. Any ideas?

share|improve this question
up vote 0 down vote accepted

What you're looking for (to spawn off Applescripts when adding new files into a "hot folder") is called "Folder Actions", and there are a number of tutorials that can be found online that should point you in the right direction.

For example, here is one: "AppleScript: Exploring the power of Folder Actions, part I"

share|improve this answer

Here is another example of a folder action. You should save the script in ~/Library/Scripts/Folder Action Scripts .

    on adding folder items to theFolder after receiving theFiles

    -- This should make the folder action wait until large files have finished copying to the folder
    set fSizes to {0}
    repeat
        tell application "System Events" to set end of fSizes to size of theFolder
        if (item -1 of fSizes) = (item -2 of fSizes) then exit repeat
        delay 1
    end repeat

    -- If you want to do something with each file ...
    repeat with aFile in theFiles
        -- your code goes here  
    end repeat

end adding folder items to

Keep in mind that if your script saves anything to the target folder, the folder action will be triggered again.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.