2013-05-21 26 views
0

所以,雖然運行此我得到一個錯誤:在它suposed如果犯規存在,它創建一個文件夾中的部分具體錯誤使文件夾

on hazelProcessFile(theFile) 
set text item delimiters to ":" 
set filename to last text item of (theFile as text) 
set text item delimiters to "." 
if filename contains "." then 
    set base to text items 1 thru -2 of filename as text 
    set extension to "." & text item -1 of filename 
else 
    set base to filename 
    set extension to "" 
end if 
set text item delimiters to {"720p", "HDTV", "x264", "IMMERSE", "-", "E01", "…", "E02", "EVOLVE"} 
set ti to text items of base 
set text item delimiters to "" 
set newbase to ti as text 
set newbase to Replace(newbase, "S0", "Season ") 
set newbase to Replace(newbase, ".", " ") 
set newbase to Replace(newbase, " ", "") 
set newbase to Replace(newbase, " ", "") 
set folderLocation to "/Volumes/LaCie/Midia/Series/" 
set folderName to newbase as text 
tell application "Finder" 
    if newbase contains "Season" then 
     if not (exists folder (POSIX file "/Volumes/LaCie/Midia/Series/" & newbase as text)) then 
      set p to path to "/Volumes/LaCie/Midia/Series/" 
      --make new folder at p with properties {name:newbase} 
      make new folder with properties {name:folderName, location:p} 
     else 
      move theFile to POSIX file "/Volumes/LaCie/Midia/Series/" & newbase as text 
      set name of result to newbase 
     end if 
    else 
     move theFile to POSIX file "/Volumes/LaCie/Midia/Filmes/" 
    end if 
end tell 
end hazelProcessFile 

on Replace(input, x, y) 
    set text item delimiters to x 
    set ti to text items of input 
    set text item delimiters to y 
    ti as text 
end Replace 

(其目的是自動排序電視連續劇)。

日誌文件:

NSLocalizedDescription = "Finder got an error: Can\U2019t make \"/Volumes/LaCie/Midia/Series/\" into type constant."; 
    NSLocalizedFailureReason = "Can\U2019t make \"/Volumes/LaCie/Midia/Series/\" into type constant."; 
    OSAScriptErrorAppAddressKey = "<NSAppleEventDescriptor: [0x0,c00c \"Finder\"]>"; 
    OSAScriptErrorAppNameKey = Finder; 
    OSAScriptErrorBriefMessageKey = "Can\U2019t make \"/Volumes/LaCie/Midia/Series/\" into type constant."; 
    OSAScriptErrorExpectedTypeKey = "<NSAppleEventDescriptor: 'enum'>"; 
    OSAScriptErrorMessageKey = "Finder got an error: Can\U2019t make \"/Volumes/LaCie/Midia/Series/\" into type constant."; 
    OSAScriptErrorNumberKey = "-1700"; 
    OSAScriptErrorOffendingObjectKey = "<NSAppleEventDescriptor: 'utxt'(\"/Volumes/LaCie/Midia/Series/\")>"; 
    OSAScriptErrorRangeKey = "NSRange: {0, 0}"; 

任何想法? 謝謝!

編輯:

所以,@lauri幫助我的運動部件,唯一錯的是,文件複製,不移動,這意味着原始文件留在同一個地方。我希望它被丟棄或者copleteley移動。有任何想法嗎?

編輯2:

所以,我實現什麼@lauri建議,我仍然有一個錯誤(在mv命令),任何想法?

on hazelProcessFile(theFile) 
    set text item delimiters to ":" 
    set filename to last text item of (theFile as text) 
    set text item delimiters to "." 
    if filename contains "." then 
     set base to text items 1 thru -2 of filename as text 
     set extension to "." & text item -1 of filename 
    else 
     set base to filename 
     set extension to "" 
    end if 
    set text item delimiters to {"WEB.DL.DD5.1.H.264.HWD", "WEB-DL.AAC2.0.H.264-NTb", "WEB-DL.DD5.1.H.264-CtrlHD", "WEB.DL.DD5.1.H.264", "PMP", "720p", "HDTV", "x264", "IMMERSE", "-", "E01", "…", "E02", "EVOLVE", "DIMENSION", "E03", "E04", "E05", "E06", "E07", "E08", "E09", "E10", "E11", "E12", "E13", "E14", "E15", "E16", "E17", "E18", "E19", "E20", "E21", "E22", "E23", "E24", "E25", "E26", "E27", "E28", "E29", "E30", "2012", "2013", "2014", "2015", "2016", "FoV", "FOV", "fov", "1080p", "X264", "AFG", "afg", "xvid", "XviD", "XVID", "INTERNAL", "PROPER", "FQM", "fqm", "LOL", "lol", "REWARD", "reward", "WEB", "DL", "AAC2", "H.264", "NTb", "CtrlHD", "DD5", "eztv", "EZTV", "WEB", "VTV", "mSD", "CTU", "hdtv", "evolve", "immerse", "+", "PublicHD", "HWD"} 
    set ti to text items of base 
    set text item delimiters to "" 
    set newbase to ti as text 
    set newbase to Replace(newbase, "S0", "Season ") 
    set newbase to Replace(newbase, "S1", "Season 1") 
    set newbase to Replace(newbase, "S2", "Season 2") 
    set newbase to Replace(newbase, ".", " ") 
    set newbase to Replace(newbase, " ", "") 
    set newbase to Replace(newbase, " ", "") 
    set newbase to Replace(newbase, " ", "") 
    set folderLocation to "/Volumes/LaCie/Midia/Series" 
    set folderName to newbase as text 
    tell application "Finder" 
     if newbase contains "Season" then 
      if not (exists folder (POSIX file "/Volumes/LaCie/Midia/Series/" & newbase as text)) then 

       -- make new folder at POSIX file "/Volumes/LaCie/Midia/Series/" with properties {name:newbase as text} 
       -- move theFile to POSIX file "/Volumes/LaCie/Midia/Series/" & newbase as text 
       do shell script "d=/Volumes/LaCie/Midia/Series/" & quoted form of newbase & " 
       mkdir -p \"$d\" 
       mv " & quoted form of POSIX path of theFile & " $d" 



      else 
       -- move theFile to POSIX file "/Volumes/LaCie/Midia/Series/" & newbase as text 
       do shell script "d=/Volumes/LaCie/Midia/Series/" & quoted form of newbase & " 
       mv " & quoted form of POSIX path of theFile & " $d" 

       set name of result to newbase 
      end if 
     else 
      -- move theFile to POSIX file "/Volumes/LaCie/Midia/Filmes/" 
      do shell script "mv " & quoted form of POSIX path of theFile & " /Volumes/LaCie/Midia/Filmes/" 
     end if 
    end tell 
end hazelProcessFile 

on Replace(input, x, y) 
    set text item delimiters to x 
    set ti to text items of input 
    set text item delimiters to y 
    ti as text 
end Replace 

回答

0

更換path toPOSIX file和使用at說明符的位置:

tell application "Finder" 
    make new folder at POSIX file "/tmp" with properties {name:"new folder"} 
end tell 

FWIW,這個問題是後續Applescript error while trying to move files with hazel

顯然,當目標位於不同的捲上時,move命令將複製文件。您可以使用do shell腳本代替:

if newbase contains "Season" then 
    do shell script "d=/Volumes/LaCie/Midia/Series/" & quoted form of newbase & " 
mkdir -p \"$d\" 
mv " & quoted form of POSIX path of theFile & " $d" 
else 
    do shell script "mv " & quoted form of POSIX path of theFile & " /Volumes/LaCie/Midia/Filmes/" 
end if 
+0

這就完美了!唯一的問題是,當我這樣做時,文件不會被移動,它只會被複制,這意味着原始文件與其使用的文件夾保持在同一文件夾中,觸發它不斷移動......任何想法如何解決ta @lauri? –

+0

我已經更新了新腳本的答案,至於我得到一個錯誤,有什麼想法? –

+0

我已經用新腳本更新了答案,至於我得到一個錯誤,任何想法@lauri? –