태그 보관물: applescript

applescript

AppleScript를 통해 휴지통에서 파일을“밀어 넣을”때 암호 프롬프트를 피하는 방법은 무엇입니까?

실수로 4,000 개가 넘는 파일을 휴지통으로 옮겼으며 파일을 원래 위치로 다시 옮기고 싶습니다. Lion은 Finder의 “Put Back”명령을 통해이 기능을 지원하지만 한 번에 하나의 파일 만 되돌릴 수 있습니다.

한 번에 한 파일 씩 파일을 올리는 프로세스를 자동화하는 AppleScript 스크립트를 찾았습니다. 밤새 스크립트를 실행했는데 대부분 작동했지만 휴지통에는 1,700 개의 파일이 남아있었습니다.

문제는 나머지 파일이 Put Back이 발생하기 전에 암호를 입력해야한다는 것입니다. 이 파일은 다른 소유자가 만든 것으로 생각합니다.

내 질문은 어떻게 해결할 수 있습니까?

삭제 취소하려는 모든 파일에 대해 비밀번호를 입력 할 필요가없는 수퍼 유저 모드로 들어가는 방법이 있습니까?

도움을 주시면 감사하겠습니다.

AppleScript는 다음과 같습니다.

  repeat 4173 times --or as many files you have

          tell application "Finder" to open trash --open the trash folder

          tell application "Finder" to activate

          tell application "System Events"

                    tell process "Finder"

  delay 0.2 -- adjust delay as needed

  key code 125 --move down to get focus on a file

  key down command --hold command key

  delay 0.2 -- adjust delay as needed

  key code 51 --hit delete

  key up command --release command

                    end tell

          end tell

  delay 0.2 -- adjust delay as needed

          tell application "Finder" to close every window --close everything for the next cycle

end repeat


답변

암호 입력을 에뮬레이트 할 수도 있습니다. keystroke "password" & return암호 대화 상자가 표시되지 않은 경우 부분은 해가되어야합니다. 이 스크립트는 몇 개의 파일로만 테스트되었으므로 여전히 수정해야 할 수도 있습니다.

tell application "Finder"
    repeat 4 times
        close windows
        open trash
        activate
        tell application "System Events"
            key code 125
            key code 51 using command down
            delay 0.2
            keystroke "password" & return
            delay 0.2
        end tell
    end repeat
    close windows
end tell

또한로 Finder를 루트로 열려고 시도했지만 sudo /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder모든 파일에서 되돌릴 수있는 동작이없는 것 같습니다.


답변