2016-05-31 24 views
0

當我購買新的DVD收藏夾時,我通常會將我的DVD收藏夾撕到我的媒體服務器,並且我決定使用Applescript幫助將完成的收藏夾移動到各自的家中。我根據電影的開頭字母,用不同的文件夾按姓名排列我的電影。例如,如果電影標題爲死機,它將被放置在名爲「D」的文件夾中。Applescript根據名稱將文件分類到正確的位置?

[我的書2TB /電影/ d/Deadpool(2016).MKV]

我希望能夠到我所有的.mkv文件拖放到「watchfolder」和使用文件夾操作,自動在有腳本把它們放在他們的地方。這是我迄今爲止,但它目前沒有工作。我該如何得到這個工作?

所有的
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 

回答

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 
+0

我知道必須有一個更簡單的方法將其刪除。 :)雖然當initialLetter是一個數字時,我如何才能將它傳遞到名爲「#」的目錄,而不是最終以目錄「1」「2」等結尾?我也想將任何以「The」開頭的電影片名發送到名爲「THE」的目錄。 –

+0

這工作,但我不得不在這裏使用或:if(characterID <65和characterID> 90) –

+0

是的,當然,我的壞。 – vadian

相關問題