2012-08-09 62 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 

請記住,如果您的腳本將任何內容保存到目標文件夾,文件夾操作將再次觸發。

相關問題