2009-09-21 4 views
0

내가 선택한 모든 트랙을 삭제하기위한 다음과 같은 애플 스크립트를 만들었습니다iTunes에서 선택한 트랙을 삭제하도록 AppleScript를 수정하려면 어떻게합니까?

property okflag : false 

-- check if iTunes is running 
tell application "Finder" 
    if (get name of every process) contains "iTunes" then set okflag to true 
end tell 
if okflag then 
    tell application "iTunes" 
     if selection is not {} then 
      repeat with this_track in selection 
       try 
        try 
         set cla to class of this_track 
         set floc to (get location of this_track) 
         delete this_track 
        on error error_message number error_number 
         display alert error_message message ("Error number: ") & error_number & "." 
        end try 
        if cla is file track then 
         my delete_the_file(floc) 
        end if 
       end try 
      end repeat 
     end if 
    end tell 
end if 

to delete_the_file(floc) 
    try 
     -- tell application "Finder" to delete floc 
     do shell script "mv " & quoted form of POSIX path of (floc as string) & " " & quoted form of POSIX path of (path to trash as string) 
    on error 
     display dialog "Track deleted, but could not be moved to trash" buttons {"Hmm"} default button 1 with icon 1 
    end try 
end delete_the_file 

내가 단일 항목을 선택하면 그것은 잘 작동하지만 내가 이상 하나를 선택했을 때 얻을 "의 위치를 ​​가져올 수 없습니다 선택 항목 2 "(오류 번호 -1728). 나는 이것이 트랙을 삭제함으로써 스크립트의 인덱스가 손상되어서 이것이라고 생각한다.

tell application "iTunes" 
    if selection is not {} then 
     set to_delete to {} 
     repeat with this_track in selection 
      try 
       set cla to class of this_track 
       set floc to (get location of this_track) 
       if cla is file track then 
        set pair to {this_track, floc} 
        set to_delete to to_delete & pair 
       end if 
      end try 
     end repeat 
     repeat with pair in to_delete 
      set the_track to item 1 of pair 
      set floc to item 2 of pair 
      delete the_track 
      my delete_the_file(floc) 
     end repeat 
    end if 
end tell 

을하지만 그때 나는 응용 프로그램의 "iTunes"의 선택 항목 1의 항목 하나를 가져올 수 없습니다 '얻을 :

은 내가 트랙 내 자신의 목록을 먼저 삭제 할 수있게하려고 거라고 생각했다. ' 나는 문제가 "this_track"이 클래스 트랙의 객체가 아니라 선택 항목이라고 생각한다. 선택 항목에서 실제 트랙 객체를 얻으려면 어떻게해야합니까?

해결 방법이 표시되지 않으면 디버깅 또는 다른 제안 사항에 대한 정보를 보내 드리겠습니다.

답변

2

변수 this_track은 개체 지정자에 대한 참조입니다. 둘러싸인 개체 지정자를 가져 오려면 contents 속성을 사용해야합니다. 두 번째 루프에서 변수 pair에 액세스하는 경우에도 마찬가지입니다. AppleScript language guide에있는 클래스 reference의 클래스 참조 섹션을 참조하십시오.

to_delete 목록이 작성되는 방식에 또 다른 문제가 있습니다. 구문 set to_delete to to_delete & pair은 쌍 목록이 아닌 단순 목록을 생성합니다. 클래스 list의 클래스 참조 섹션을 AppleScript language guide에 참조하십시오.

tell application "iTunes" 
    if selection is not {} then 
     set to_delete to {} 
     repeat with this_track in selection 
      try 
       set cla to class of this_track 
       set floc to (get location of this_track) 
       if cla is file track then 
        set pair to {contents of this_track, floc} 
        copy pair to end of to_delete 
       end if 
      end try 
     end repeat 
     repeat with pair in to_delete 
      set the_track to item 1 of contents of pair 
      set floc to item 2 of contents of pair 
      delete the_track 
      my delete_the_file(floc) 
     end repeat 
    end if 
end tell 
+0

나는 당신의 변화를 만들어 오류를 가지고 : 여기

이 버그가 제거 된 두 번째 스크립트의 버전의 '<의 41009 ID> 항목 1 <의 가져올 수 없습니다> 아이디 40953 of <> 응용 프로그램 "iTunes"의 ID 40. –

+0

답변을 업데이트 주셔서 감사합니다. AppleScript를 디버깅하는 방법을 알아야 할 것 같습니다. 질문을하겠습니다. –

관련 문제