2017-04-09 5 views
0

내 아이튠즈 아티스트 및 장르 목록을 내 라이브러리에서 가져 오려고합니다. AppleScript는 일부 작업에서 느려질 수 있으며 이러한 상황에서 나는 속도에 많은 타협을 할 수 없습니다. 내 코드에서 할 수있는 추가 리팩터링이 있습니까?AppleScript를 통해 고유 한 iTunes 아티스트 목록보기

tell application "iTunes" 
    -- Get all tracks 
    set all_tracks to shared tracks 

    -- Get all artists 
    set all_artists to {} 
    repeat with i from 1 to count items in all_tracks 
     set current_track to item i of all_tracks 
     set current_artist to genre of current_track 
     if current_artist is not equal to "" and current_artist is not in all_artists then 
      set end of all_artists to current_artist 
     end if 
    end repeat 
    log all_artists 
end tell 

난 그냥 잘 모르는 것 같아요 아이튠즈에서 아티스트 또는 장르의 목록을 얻을 수있는 쉬운 방법이 있어야합니다 같은 느낌 ...

+0

DougScripts를 확인한 적이 있습니까? 그곳에는 많은 스크립트가 있습니다. 당신이 원한다면 구체적으로 하나가 있고, 선택하면 txt 파일로 내보낼 수 있습니다. 나는 지금 당장 그 이름을 기억할 수는 없지만 74GB의 음악을 빨리 만들었습니다. – Chilly

답변

1

당신이 얻을 경우 많은 애플 이벤트를 저장할 수 있습니다 예 : 트랙 개체가 아닌 속성 값 목록

tell application "iTunes" 
    -- Get all tracks 
    tell shared tracks to set {all_genres, all_artists} to {genre, artist} 
end tell 

문자열 목록을 구문 분석하면 Apple 이벤트가 전혀 사용되지 않습니다.

-- Get all artists 
set uniqueArtists to {} 
repeat with i from 1 to count items in all_artists 
    set currentArtist to item i of all_artists 
    if currentArtist is not equal to "" and currentArtist is not in uniqueArtists then 
     set end of uniqueArtists to currentArtist 
    end if 
end repeat 
log uniqueArtists 

코코아 (AppleScriptObjC)의 도움으로 훨씬 빨라졌습니다. NSSet은 고유 한 개체가 포함 된 컬렉션 형식입니다. 배열에서 집합을 만들면 모든 중복이 암시 적으로 제거됩니다. allObjects() 메서드는 배열을 다시 배열로 바꿉니다.

use framework "Foundation" 

tell application "iTunes" to set all_artists to artist of shared tracks 
set uniqueArtists to (current application's NSSet's setWithArray:all_artists)'s allObjects() as list 
+0

쿨, 나는 이것을 돕기 위해 objective-c를 사용하는 것에 대해 생각하지 않았습니다. 대답의 첫 부분에서 사용한 짧은 구문에 대해서도 몰랐습니다. 고맙습니다! –