0

我正在尝试创建一个applescript,当该文件夹添加到目录时,它实际上会从文件夹中提取电影文件。例如,当我将包含电影和其他文件的文件夹添加到“电影”目录时,我希望保留电影文件本身,删除其他不必要的文件。

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

到目前为止,这是我的尝试。我已经从不同的试验中注释掉了行,为了简单起见,我现在使用 ~/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
4

1 回答 1

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
于 2013-09-07T11:37:52.537 回答