2012-10-03 4 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

업데이트 : 위와 같은 대화 상자를 표시하는 방법을 알고이 문제는 내가 구현하는 방법을 모르는 인 애플 스크립트 로직을 "대체하거나 생략, 중복". 게다가,이 라인을 유지하려면 :

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

위와 같은 대화 상자를 표시하는 방법을 알고 있습니다. 문제는 "복제를 구현하는 방법을 모르겠습니다. AppleScript에서 로직을 변경, 대체 또는 건너 뛰기 만하면됩니다. –

+0

대체 및 건너 뛰기 논리가 내 대답에 포함됩니다. – adayzdone

+0

아, 처음에는 눈치 채지 못했습니다. 죄송합니다. 게다가, '반복'을 사용하는 대신 'destinFolder'로 '이동 선택'을 계속 사용하는 방법이 있습니까? 감사. –

0

애플 스크립트를 사용하여 찾기 복사 UI를 표시 할 수 없습니다. 자신 만의 UI를 구현해야합니다.
스크립트에 표시됩니다.
enter image description here

Mac Finder native copy dialog 문서를 참조하십시오.