Applescript文件夹操作支持更改/更改/更新的文件?

时间:2011-06-25 05:57:38

标签: applescript

文件夹项目更改时的文件夹操作不存在吗?我希望我的脚本在我更新文件的时候运行。我在documentation中没有看到任何对它的引用。是否有某种替代方案我缺少,因为这种接缝非常疯狂而没有。

on adding folder items to this_folder after receiving added_files
    do shell script "anything"
end adding folder items to

on removing folder items from this_folder after losing removed_files
    do shell script "anything"
end removing folder items from

-- does not exits?!?
on changing folder items in this_folder after updating changed_files
    do shell script "anything"
end changing folder items in

4 个答案:

答案 0 :(得分:2)

不,不直接存在。但是,使用一个空闲处理程序可以完成类似的操作,该处理程序监视文件夹中的文件以查看其修改日期是否已更改,并对文件执行操作。

答案 1 :(得分:2)

还有文件夹操作的替代方法。您使用launchd并设置监视路径。使用监视路径,只要您正在观看的文件夹中发生更改,代码就会运行。文件夹操作和launchd操作之间的最大区别在于,对于launchd操作,您不知道哪些文件发生了更改。你只知道发生了一些变化。因此,您的代码必须弄清楚实际的变化,但在您的情况下这不应该太难,因为如果您正在寻找更新的文件,您只需检查文件的修改日期。

如果您想尝试,可以google for launchd和观看路径。

答案 2 :(得分:1)

rsync -va '/source/path/' '/destination/path/'如何使用Lingon将这个简单的命令设置为用户守护程序,例如,每10秒运行一次?

答案 3 :(得分:1)

我发现使用Automator很容易做到这一点并且仅在某些情况下有效,所以试试看它是否有帮助。当您在OSX中创建/修改文件夹内容时,一个名为.DS_Store的隐藏操作系统文件会被写入该文件夹,它对用户来说是一个无用的文件,但它可以触发文件夹操作。话虽如此,我在我的文件夹操作中的Run Shell Script操作中使用rsync。完成操作后,同步I然后删除.DS_Store文件。

以下是我的例子:

function ConvertDegreeAngleToDecimal(degrees, minutes, seconds )
{
    //Decimal degrees = 
    //   whole number of degrees, 
    //   plus minutes divided by 60, 
    //   plus seconds divided by 3600

    return degrees + (minutes/60) + (seconds/3600);
}

然后,当您下次修改该目录中的文件/文件夹时,文件夹操作将启动,并且该过程将重复。

我希望这会有所帮助......