2

脚本如下:

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继续下一个文件移动。就像下面的图片一样。

在此处输入图像描述

更新:我知道如何像上面那样显示一个对话框,问题是我不知道如何在 AppleScript 中实现“复制、替换或跳过”逻辑。此外,我想保留这条线:

move selection to destinFolder

因为这行代码在单个对话框中显示了正确的移动进度百分比,所以使用repeat将失去该好处。

4

2 回答 2

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
于 2012-10-03T14:05:45.800 回答
0

使用 applescript 显示查找器副本 UI 是不可能的。您应该实现自己的 UI。
你的脚本会显示这个。
在此处输入图像描述

看看Mac Finder 原生复制对话框文章。

于 2012-10-03T13:26:07.723 回答