从Applescript中获取当前曲目的艺术作品

时间:2013-06-08 01:58:34

标签: applescript itunes artwork

我正在尝试制作一个脚本来拉出当前播放曲目的图稿并将其写入文件。我已经检查了一些指南,但它们似乎都没有用,有什么提示吗?

tell application "iTunes"
write artwork 1 to "path:to:desktop" of type("JPEG")
end tell

说实话,我不知道我在做什么。有人觉得有帮助吗?

由于

1 个答案:

答案 0 :(得分:7)

您可以将raw data of artwork 1 of current track写入文件:

-- get the raw bytes of the artwork into a var
tell application "iTunes" to tell artwork 1 of current track
    set srcBytes to raw data
    -- figure out the proper file extension
    if format is «class PNG » then
        set ext to ".png"
    else
        set ext to ".jpg"
    end if
end tell

-- get the filename to ~/Desktop/cover.ext
set fileName to (((path to desktop) as text) & "cover" & ext)
-- write to file
set outFile to open for access file fileName with write permission
-- truncate the file
set eof outFile to 0
-- write the image bytes to the file
write srcBytes to outFile
close access outFile

您也可以使用http://dougscripts.com/itunes/scripts/ss.php?sp=savealbumart,但不包含源代码。