Applescript 将文件夹添加到目录时,如何从文件夹中移动特定文件?
我正在尝试创建一个applescript,当文件夹添加到目录时,它将从文件夹中提取一个电影文件。例如,当我将包含电影和其他文件的文件夹添加到我的“Movies”目录时,我希望保留电影文件本身,删除其他不必要的文件 我已经能够使这项工作与手动脚本,但我想它自动运行添加。我认为问题的一部分在于如何处理传入的文件夹。我不确定“这些项目”是如何处理的。我试着像处理文件一样处理它,如果它是文件夹中的文件列表 这是我迄今为止的尝试。我已经从不同的试用版中注释了几行,为了简单起见,我现在使用~/Desktop作为我的目标文件夹Applescript 将文件夹添加到目录时,如何从文件夹中移动特定文件?,applescript,Applescript,我正在尝试创建一个applescript,当文件夹添加到目录时,它将从文件夹中提取一个电影文件。例如,当我将包含电影和其他文件的文件夹添加到我的“Movies”目录时,我希望保留电影文件本身,删除其他不必要的文件 我已经能够使这项工作与手动脚本,但我想它自动运行添加。我认为问题的一部分在于如何处理传入的文件夹。我不确定“这些项目”是如何处理的。我试着像处理文件一样处理它,如果它是文件夹中的文件列表 这是我迄今为止的尝试。我已经从不同的试用版中注释了几行,为了简单起见,我现在使用~/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
将此文件夹操作附加到“Movies”目录:
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
我已经很多年没有写过Applescript了,然而,这难道不能在Automator中完成吗?它工作得很完美。非常感谢。