Getting artwork from current track in Applescript

杀马特。学长 韩版系。学妹 提交于 2019-11-27 16:55:22

问题


I'm trying to make a script to pull the artwork of the currently playing track and write it to a file. I've checked out a few guides but none of them seem to work, any tips?

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

To be honest I've no idea what I'm doing. Anyone feeling helpful?

Thanks


回答1:


You can write raw data of artwork 1 of current track to a file:

-- 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

You might also use http://dougscripts.com/itunes/scripts/ss.php?sp=savealbumart, but it doesn't include source code.



来源:https://stackoverflow.com/questions/16995273/getting-artwork-from-current-track-in-applescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!