2013-11-21 24 views
0

我有一個文件夾操作,當新文件添加到文件夾並且它工作(有點)時,通過Messages向我發送文本消息。這裏是:「Messages」文本的Applescript文件夾操作,需要調整

on adding folder items to this_folder after receiving added_items 
    set added_Items_List to {} 
    set dateString to (current date) as string 
    set theBody to "New items have been added to " & name of (info for this_folder) & ": " 

    tell application "Messages" 
     set theBuddy to buddy "E:[email protected]" of service "E:[email protected]" 
     send theBody & dateString to theBuddy 
    end tell 

end adding folder items to 

問題是,如果添加200個文件,它會發送200個文本。

我希望它只是在添加第一個文件時向我發送消息,然後在給定時間間隔內忽略,例如30分鐘。這可能嗎?

此外,我希望它獲得文件夾路徑,至少有一個文件夾從它的位置。

非常感謝!

回答

0

嘗試使用臨時文件。你可以得到的文件夾與POSIX path of this_folder完整路徑:

on adding folder items to this_folder after receiving added_items 
    do shell script "f=${TMPDIR}messagesfolderaction;[[ ! -e $f || $(stat -f%m $f) -le $(date +%s)-1800 ]]&&touch $f||echo a" 
    if result is not "" then return 
    set body to "New items have been added to " & POSIX path of this_folder & (current date) as text 
    tell application "Messages" 
     send body to buddy "E:[email protected]" of service "E:[email protected]" 
    end tell 
end adding folder items to 
+0

嗯..有什麼我需要正確的,除了在地址的域名呢?當我啓用它時似乎沒有發生。謝謝! – scottl31

+0

@ scottl31腳本中有錯誤,但我編輯了它。 – user495470

+0

真的很好!我添加了一個文件並獲得了消息,然後添加了幾個文件並沒有消息。大!現在我等待30分鐘後再添加更多。 只有一個問題:如果我想發送給多個人,那麼我是否只需要將地址更改爲正確的「將身體發送給好友...」行? – scottl31