你可以嘗試這樣的事情:
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
我知道如何顯示上面的對話框,問題是我不知道如何實現「dupl在AppleScript中替換或替換「邏輯」。 –
替換並跳過邏輯在我的答案中。 – adayzdone
哦,我沒有注意到,乍一看,對不起。除此之外,有沒有辦法繼續使用'移動選擇到destinFolder'而不是'重複'?謝謝。 –