我通常会将我的DVD收藏品翻录到我的媒体服务器上,因为我购买了新的DVD收藏夹,并且我决定使用Applescript来帮助将完成的剪辑移动到他们各自的家中。我根据电影的开头字母用不同的文件夹按名称对电影进行排序。例如,如果电影标题是Deadpool,它将被放置在名为" D"的文件夹中。
[My Book 2TB / Movies / D / Deadpool(2016).mkv]
我希望能够将所有.mkv文件放入"观看文件夹"并使用“文件夹操作”自动将脚本放在其位置。这是我到目前为止所做的,但目前还没有。我怎么能这样工作?
set theFolder to ((path to desktop) as text) & "Movie Rip Drop"
set theFiles to every item of theFolder
on adding folder items to theFolder after receiving theFiles
repeat with aFile in theFiles
tell application "Finder"
if aFiles's name begins with "A" then
move aFile to "My Book 2TB:Movies:A"
else if aFiles's name begins with "B" then
move aFile to "My Book 2TB:Movies:B"
else if aFiles's name begins with "C" then
move aFile to "My Book 2TB:Movies:C"
else if aFiles's name begins with "D" then
move aFile to "My Book 2TB:Movies:D"
else if aFiles's name begins with "E" then
move aFile to "My Book 2TB:Movies:E"
else if aFiles's name begins with "F" then
move aFile to "My Book 2TB:Movies:F"
else if aFiles's name begins with "G" then
move aFile to "My Book 2TB:Movies:G"
else if aFiles's name begins with "H" then
move aFile to "My Book 2TB:Movies:H"
else if aFiles's name begins with "I" then
move aFile to "My Book 2TB:Movies:I"
else if aFiles's name begins with "J" then
move aFile to "My Book 2TB:Movies:J"
else if aFiles's name begins with "K" then
move aFile to "My Book 2TB:Movies:K"
else if aFiles's name begins with "L" then
move aFile to "My Book 2TB:Movies:L"
else if aFiles's name begins with "M" then
move aFile to "My Book 2TB:Movies:M"
else if aFiles's name begins with "N" then
move aFile to "My Book 2TB:Movies:N"
else if aFiles's name begins with "O" then
move aFile to "My Book 2TB:Movies:O"
else if aFiles's name begins with "P" then
move aFile to "My Book 2TB:Movies:P"
else if aFiles's name begins with "Q" then
move aFile to "My Book 2TB:Movies:Q"
else if aFiles's name begins with "R" then
move aFile to "My Book 2TB:Movies:R"
else if aFiles's name begins with "S" then
move aFile to "My Book 2TB:Movies:S"
else if aFiles's name begins with "The" then
move aFile to "My Book 2TB:Movies:The"
else if aFiles's name begins with "T" then
move aFile to "My Book 2TB:Movies:T"
else if aFiles's name begins with "U" then
move aFile to "My Book 2TB:Movies:U"
else if aFiles's name begins with "V" then
move aFile to "My Book 2TB:Movies:V"
else if aFiles's name begins with "W" then
move aFile to "My Book 2TB:Movies:W"
else if aFiles's name begins with "X" then
move aFile to "My Book 2TB:Movies:X"
else if aFiles's name begins with "Y" then
move aFile to "My Book 2TB:Movies:Y"
else if aFiles's name begins with "Z" then
move aFile to "My Book 2TB:Movies:Z"
else
move aFile to "My Book 2TB:Movies:#"
end if
end tell
end repeat
end adding folder items to
答案 0 :(得分:2)
首先,永远不会执行文件夹操作事件处理程序之外的代码。
shell命令ditto
可以同时复制项目和创建中间目录。
因此,获取文件名的第一个字母,复制该项目并将其删除在热文件夹中
on adding folder items to theFolder after receiving theFiles
repeat with aFile in theFiles
tell application "System Events" to set fileName to name of aFile
if fileName starts with "The" then
set subFolderName to "THE"
else
set subFolderName to first character of fileName
set characterID to id of subFolderName
if (characterID < 65 or characterID > 90) then set subFolderName to "#"
end if
set destination to quoted form of ("/Volumes/My Book 2TB/Movies/" & subFolderName & "/" & fileName)
do shell script "usr/bin/ditto " & quoted form of POSIX path of aFile & space & destination
do shell script "/bin/rm " & quoted form of POSIX path of aFile
end repeat
end adding folder items to