2017-01-25 9 views
0

AppleScript를 사용하지 않고 iTunes 보관함 디렉토리에있는 트랙을 확인하려고합니다.AppleScript - 라이브러리의 모든 iTunes 트랙을 반복 재생할 때 성능이 좋지 않음

다음 스크립트는 정말 (라이브러리에 대한 8000 트랙있다) 각 트랙에 대한 2 초 복용 느린입니다 : 또한 다음을 시도

#!/usr/bin/osascript 
tell application "iTunes" 

     repeat with l in (location of every file track) 
       set fileName to (POSIX path of l) 
       if fileName does not start with "/Users/user/Music/iTunes/iTunes Media/" then 
         log fileName 
       end if 
     end repeat 

end tell 

하지만 동일한 성능 :

#!/usr/bin/osascript 
tell application "iTunes" 

     repeat with l in (location of every file track) 
       POSIX path of l does not start with "/Users/user/Music/iTunes/iTunes Media/" 
     end repeat 

end tell 

한편 iTunes는 꽤 반응이 없습니다.

어리석은 짓을하고 있어야하지만 무엇을 알아낼 수는 없습니다.

이것은 2015 27M iMac의 OS X El Capitan에 있습니다.

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

건배

답변

0

당신은 극적으로 키워드 get

를 사용하여 스크립트의 속도를 높일 수 있습니다
repeat with l in (get location of every file track) 

의 차이는 다음 목록은 각 반복

  • 에서 검색되는 get없이

    • get으로 목록이 한 번 검색됩니다.
  • +0

    자리에! 감사 – user1905449

    0

    두 가지 문제 : 애플 이벤트의

    1. 보내기 많이 비싸다. repeat with l in (location of every file track)은 각 트랙에 대해 get 이벤트를 별도로 보냅니다 (get location of file track 1, get location of file track 2, ...). 먼저 모든 위치 목록을 가져온 다음 반복합니다.

    2. 엉터리 구현으로 인해 AppleScript 목록 항목을 가져 오는 데 걸리는 시간이 목록의 길이에 따라 선형 적으로 증가합니다. 따라서 큰 목록을 반복 할 때 성능이 향상됩니다 (O(n) 효율성 대신 O(n*n)). 참조를 통해 목록 항목을 참조 (예 : 스크립트 객체 속성에 목록을 고정시킨 다음 참조)하여 불쾌한 해킹으로 O(n)으로 가져올 수 있습니다.

    예 :

    set iTunesFolder to POSIX path of (path to music folder) & "iTunes/iTunes Media/" 
    
    tell application "iTunes" 
        script 
         property fileLocations : location of every file track 
        end script 
    end tell 
    repeat with l in fileLocations of result 
        set fileName to (POSIX path of l) 
        if fileName does not start with iTunesFolder then log fileName 
    end repeat