2016-02-28 62 views
0

我制作了一个自动工作流程,可以将歌曲添加到我的iTunes资料库,并通过艺术家姓名,专辑名称和歌曲名称设置他们的信息。然而,当我导入它们时,轨道是没有保护的,因此我一直在寻找自动添加艺术品的方法。其中一种方法是使用iTunes“Get Album Artwork”。问题在于,如果它提供了它,它往往不会给出非常好的作品。如何使用AppleScript自动将艺术作品添加到iTunes歌曲?

我决定下载歌曲的作品,我没有将作品存储在我的“下载”文件夹中。我传入我的脚本中的input是我想作为艺术作品添加到歌曲中的.jpg文件。问题是,每当我运行这个脚本时,它说它不能将别名文件变成文件类型。错误信息如下:

Can’t make alias "Macintosh HD:Users:Nilay:Downloads:Avicii - True - Hey Brother.jpg" into type file.

没有理由不应该能够找到该文件,因为我发现使用Automator的“过滤器Finder项目”,所以我知道这是通过在正确的文件的文件。

我试图通过文件的文本而不是实际的文件,但仍然导致相同的消息。前几个评论是我尝试解决这个错误消息的几种方法,但是,唉,没有工作。

我想知道如果有人知道如何解决这个错误信息或其他方式,我可以添加自定义艺术作品的歌曲,而无需手动去iTunes - >选择歌曲 - >获取信息 - >艺术品 - >添加艺术品。如果有人能够解释如何使用AppleScript或Workflow自动执行此操作,也是可行的。谢谢!!!

on run {input, parameters} 

    --set jpegFilename to input 
    --set jpegFilename to "/path/to/some/artwork.jpg" 
    --set jpegFile to (POSIX file jpegFilename) 
    --set jpegFile to (jpegFilename as POSIX file) 
    --tell application "System Events" to set jpegFile to (input as POSIX file) 
    set jpegFile to input 

    tell application "Image Events" 
     set myImage to open (jpegFile as file) 
     -- the below line needs HFS syntax pathname, eg: MyComputer:Users:liquidx: 
     -- save myImage as PICT in (file ":path:to:some:temporary.pict") 
     save myImage as PICT in (POSIX file jpegFile) 
     close myImage 
    end tell 

    tell application "iTunes" 
     set myTrack to current track 
     set artworkCount to count of artwork of myTrack 
     -- the below line needs HFS syntax pathname, eg: MyComputer:Users:liquidx: 
     -- set myArt to read (file ":path:to:some:temporary.pict") from 513 as picture 
     set myArt to read (POSIX file jpegFile) from 513 as picture 
     if artworkCount > 0 then 
      set data of artwork (artworkCount + 1) of current track to myArt 
     else 
      set data of artwork 1 of current track to myArt 
     end if 
    end tell 

    tell application "Image Events" 
     -- delete (file ":path:to:some:temporary.pict") 
     delete (POSIX file jpegFile) 
    end tell 

end run 

回答

0

input是别名说明符的列表,首先你需要一个重复循环

repeat with jpegFile in input 

或获取列表的第一项

set jpegFile to item 1 of input 

然后open命令Image Events无论如何期望别名说明符,因此不需要任何强制。

set myImage to open jpegFile 
+0

如你所说的我做了,我仍然收到此错误:图片活动得到了一个错误:无法获取POSIX文件(化名的“Macintosh HD:用户:Nilay:下载:航空工业第二集团公司 - 真 - 嘿兄弟.JPG“)。 – Nilay

+0

如果你已经有了别名,不要使用POSIX文件转换。 – vadian

相关问题