2012-10-03 28 views
2

的腳本如下:我想告訴Finder使用AppleScript移動文件。但我不知道如何處理重複數據刪除/置換/跳過

tell application "Finder" 

    set destinFolder to (choose folder) 

    try 
     move selection to destinFolder 
    on error vMessage number -15267 
     display dialog "" & vMessage 
    end try 

end tell 

基本上,如果具有相同名稱的文件中的目標文件夾中已經存在,我希望用戶可以選擇複製,替換或跳過該文件,然後使用AppleScript繼續下一個文件移動。就像下面的圖片一樣。

enter image description here

更新:我知道如何顯示像上面的對話框,問題是我不知道如何實現「複製,替換或只是跳過」邏輯的AppleScript。而且,我想保留此行:

move selection to destinFolder 

因爲這行代碼顯示一個對話框適當的運動進度百分比,使用repeat將失去優勢。

回答

2

你可以嘗試這樣的事情:

set destinFolder to (choose folder) 
set destItems to every paragraph of (do shell script "ls " & quoted form of (POSIX path of destinFolder)) 

tell application "Finder" 
    set mySelection to selection 
    repeat with anItem in mySelection 
     set itemName to anItem's name 
     if itemName is in destItems then 
      display alert "An item named " & itemName & " already exists in this location. Do you want to replace it with the one you're moving?" buttons {"Skip", "Replace"} default button "Replace" 
      if button returned of the result = "Replace" then move anItem to destinFolder with replacing 
     else 
      try 
       move anItem to destinFolder 
      end try 
     end if 
    end repeat 
end tell 

或本:

set destinFolder to (choose folder) 

tell application "Finder" 
    set mySelection to selection 
    repeat with anItem in mySelection 

     try 
      move anItem to destinFolder 
     on error errMsg number errNum 
      if errNum = -15267 then 
       display alert "An item named " & itemName & " already exists in this location. Do you want to replace it with the one you're moving?" buttons {"Skip", "Replace"} default button "Replace" 
       if button returned of the result = "Replace" then move anItem to destinFolder with replacing 
      else 
       tell me 
        activate 
        display alert errMsg & return & return & "Error number" & errNum buttons "Cancel" 
       end tell 
      end if 
     end try 

    end repeat 
end tell 

編輯 這個腳本不會給你一個選擇的存在於目標文件夾中的每個項目

set destinFolder to (choose folder) 

tell application "Finder" 
    set mySelection to selection 
    try 
     move mySelection to destinFolder 
    on error errMsg number errNum 
     if errNum = -15267 then 
      display alert "One or more items already exist in this location. Do you want to replace them with the ones you're moving?" buttons {"Skip", "Replace"} default button "Replace" 
      if button returned of the result = "Replace" then move mySelection to destinFolder with replacing 
     else 
      tell me 
       activate 
       display alert errMsg & return & return & "Error number" & errNum buttons "Cancel" 
      end tell 
     end if 
    end try 

end tell 
+0

我知道如何顯示上面的對話框,問題是我不知道如何實現「dupl在AppleScript中替換或替換「邏輯」。 –

+0

替換並跳過邏輯在我的答案中。 – adayzdone

+0

哦,我沒有注意到,乍一看,對不起。除此之外,有沒有辦法繼續使用'移動選擇到destinFolder'而不是'重複'?謝謝。 –

0

它不可能使用applescript顯示查找器複製UI。你應該實現你自己的用戶界面。
你的腳本會顯示這個。
enter image description here

看看Mac Finder native copy dialog文章。

相關問題