将该文件夹添加到目录中时,如何从文件夹中移动特定文件?

时间:2013-09-07 04:09:41

标签: applescript

我正在尝试创建一个AppleScript,当该文件夹添加到目录时,该文件基本上会从文件夹中提取电影文件。例如,当我将包含电影和其他文件的文件夹添加到我的“电影”目录时,我想留下电影文件本身,删除其他不需要的文件。

我已经能够使用手动脚本完成这项工作,但我希望它能够在添加时自动运行。我认为问题的一部分是处理进来的文件夹。我不确定如何处理“these_items”。我试过把它当作文件处理,如果它是文件夹中的文件列表。

到目前为止,这是我的尝试。我从不同的试验中注释了一行,为了简单起见,我现在使用〜/ Desktop作为我的目标文件夹。

on adding folder items to this_folder after receiving these_items
tell application "Finder"
    --if kind of these_items is "Folder" then
    --set this_folder to (path to these_items)
    set this_list to every file of these_items
    --repeat with i in this_list
    --set this_list2 to every file of i
    repeat with i from 1 to number of items in this_list
        if (name of i) ends with ".mp4" then
            move i to (path to desktop folder)
            move i to trash
        end if
    end repeat
    --end repeat
    --end if
end tell

end adding folder items to

1 个答案:

答案 0 :(得分:1)

将此文件夹操作附加到“电影”目录:

on adding folder items to theFolder after receiving theItems
    set destFolder to path to desktop

    repeat with anItem in theItems
        tell application "Finder"
            if kind of anItem is "Folder" then
                move (files of (entire contents of anItem) whose name extension = "mp4") to destFolder
                delete anItem
            else if name extension of anItem = "mp4" then
                move anItem to destFolder
            else
                delete anItem
            end if
        end tell
    end repeat
end adding folder items to