通过AppleScript获取独特iTunes艺术家列表

通过AppleScript获取独特iTunes艺术家列表,applescript,itunes,Applescript,Itunes,我正试图从我的图书馆中获得独特的iTunes艺术家和流派的列表。AppleScript在某些操作中可能会很慢,在这种情况下,我不能在速度上妥协太多。我可以对我的代码做进一步的重构吗 tell application "iTunes" -- Get all tracks set all_tracks to shared tracks -- Get all artists set all_artists to {} repeat with i from 1

我正试图从我的图书馆中获得独特的iTunes艺术家和流派的列表。AppleScript在某些操作中可能会很慢,在这种情况下,我不能在速度上妥协太多。我可以对我的代码做进一步的重构吗

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

我觉得应该有一种更简单的方法从iTunes中获取我不知道的艺术家或流派的列表…

如果您获取属性值列表,而不是轨迹对象,则可以保存许多Apple事件

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

例如,如果获得属性值列表而不是轨迹对象,则可以保存许多Apple事件

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

你退房了吗?那里有大量运行速度极快的脚本。有一个专门为你想要的,可以导出到一个txt文件,如果你选择。我现在记不起它的名字了,但它很快就完成了我74gb的音乐?那里有大量运行速度极快的脚本。有一个专门为你想要的,可以导出到一个txt文件,如果你选择。我现在记不起它的名字了,但是它很快就完成了我74gb的音乐。很酷,我没有想过用objective-c来帮助我。我也不知道你在回答的第一部分中使用的简短语法。非常感谢。很酷,我没有想过用objective-c来帮助解决这个问题。我也不知道你在回答的第一部分中使用的简短语法。非常感谢。