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

このコード行は、1 つのダイアログで適切な移動の進行状況を示すため、 を使用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 に答える