2012-08-09 60 views
2

我想写一些将检测某个指定目录中的新文件。我最好希望这个脚本能够无限期地继续运行,并且每当我看到一个新文件时,我都可以将它复制并移动到别的地方。我知道这一定是可能的,因为Dropbox可以做到这一点,但我不知道如何得到这个工作或从哪里开始。有任何想法吗?Automator或Applescript,检测文件夹中的新文件

回答

1

这里是一个文件夹操作的另一个例子。您应该将脚本保存在〜/ 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 

请记住,如果您的脚本将任何内容保存到目标文件夹,文件夹操作将再次触发。

相关问题