【发布时间】:2016-09-24 03:44:16
【问题描述】:
我正在尝试创建一个应用程序,将桌面背景设置为在 iTunes 中播放的当前歌曲的专辑封面,但遇到了一个问题,即我的脚本无法读取 Apple Music 歌曲的专辑封面,除非它已被添加到用户的音乐收藏或播放列表中。
目前我正在使用this code 提取专辑封面。
-- 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
有人知道为什么直接从 Apple Music 播放时这不起作用吗?
因此,我可以将一首 Apple Music 歌曲添加到我的资料库或播放列表中,并且我的脚本可以读取其专辑封面(不必下载歌曲),但例如,当只是浏览 New 或 For You 部分时,并播放一首歌,我的脚本将无法读取它并且我的应用程序将崩溃。
任何建议都将不胜感激,因为我希望任何希望它能够使用此应用程序的人。
【问题讨论】:
标签: macos applescript itunes itunesartwork apple-music